Inheritance: XmlSchemaObject
Example #1
0
        //<appinfo
        //  source = anyURI>
        //  Content: ({any})*
        //</appinfo>
        internal static XmlSchemaAppInfo Read(XmlSchemaReader reader, ValidationEventHandler h, out bool skip)
        {
            skip = false;
            XmlSchemaAppInfo appinfo = new XmlSchemaAppInfo();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != "appinfo")
            {
                error(h, "Should not happen :1: XmlSchemaAppInfo.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            appinfo.LineNumber   = reader.LineNumber;
            appinfo.LinePosition = reader.LinePosition;
            appinfo.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "source")
                {
                    appinfo.source = reader.Value;
                }
                else
                {
                    error(h, reader.Name + " is not a valid attribute for appinfo", null);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                appinfo.Markup = new XmlNode [0];
                return(appinfo);
            }

            //Content {any}*
            //FIXME: This is a pure Quick Hack; There must be a another method;
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.AppendChild(xmldoc.ReadNode(reader));
            XmlNode root = xmldoc.FirstChild;

            if (root != null && root.ChildNodes != null)
            {
                appinfo.Markup = new XmlNode[root.ChildNodes.Count];
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    appinfo.Markup[i] = root.ChildNodes[i];
                }
            }
            if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)
            {
                skip = true;
            }
            return(appinfo);
        }
Example #2
0
		//<appinfo
		//  source = anyURI>
		//  Content: ({any})*
		//</appinfo>
		internal static XmlSchemaAppInfo Read(XmlSchemaReader reader, ValidationEventHandler h, out bool skip)
		{
			skip = false;
			XmlSchemaAppInfo appinfo = new XmlSchemaAppInfo();
			reader.MoveToElement();

			if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != "appinfo")
			{
				error(h,"Should not happen :1: XmlSchemaAppInfo.Read, name="+reader.Name,null);
				reader.SkipToEnd();
				return null;
			}

			appinfo.LineNumber = reader.LineNumber;
			appinfo.LinePosition = reader.LinePosition;
			appinfo.SourceUri = reader.BaseURI;

			while(reader.MoveToNextAttribute())
			{
				if(reader.Name == "source")
				{
					appinfo.source = reader.Value;
				}
				else
				{
					error(h,reader.Name + " is not a valid attribute for appinfo",null);
				}
			}

			reader.MoveToElement();
			if(reader.IsEmptyElement) {
				appinfo.Markup = new XmlNode [0];
				return appinfo;
			}

			//Content {any}*
			//FIXME: This is a pure Quick Hack; There must be a another method;
			XmlDocument xmldoc = new XmlDocument();
			xmldoc.AppendChild(xmldoc.ReadNode(reader));
			XmlNode root = xmldoc.FirstChild;
			if(root != null && root.ChildNodes != null)
			{
				appinfo.Markup = new XmlNode[root.ChildNodes.Count];
				for(int i=0;i<root.ChildNodes.Count;i++)
				{
					appinfo.Markup[i] = root.ChildNodes[i];
				}
			}
			if(reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)
				skip = true;
			return appinfo;
		}
Example #3
0
        internal static XmlSchemaAppInfo Read(XmlSchemaReader reader, ValidationEventHandler h, out bool skip)
        {
            skip = false;
            XmlSchemaAppInfo xmlSchemaAppInfo = new XmlSchemaAppInfo();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "appinfo")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAppInfo.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaAppInfo.LineNumber   = reader.LineNumber;
            xmlSchemaAppInfo.LinePosition = reader.LinePosition;
            xmlSchemaAppInfo.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "source")
                {
                    xmlSchemaAppInfo.source = reader.Value;
                }
                else
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for appinfo", null);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                xmlSchemaAppInfo.Markup = new XmlNode[0];
                return(xmlSchemaAppInfo);
            }
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.AppendChild(xmlDocument.ReadNode(reader));
            XmlNode firstChild = xmlDocument.FirstChild;

            if (firstChild != null && firstChild.ChildNodes != null)
            {
                xmlSchemaAppInfo.Markup = new XmlNode[firstChild.ChildNodes.Count];
                for (int i = 0; i < firstChild.ChildNodes.Count; i++)
                {
                    xmlSchemaAppInfo.Markup[i] = firstChild.ChildNodes[i];
                }
            }
            if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)
            {
                skip = true;
            }
            return(xmlSchemaAppInfo);
        }
 private void Write10_XmlSchemaAppInfo(string n, string ns, XmlSchemaAppInfo o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(XmlSchemaAppInfo)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.EscapeName = false;
         base.WriteStartElement(n, ns, o, false, o.Namespaces);
         if (needType)
         {
             base.WriteXsiType("XmlSchemaAppInfo", "http://www.w3.org/2001/XMLSchema");
         }
         base.WriteAttribute("source", "", o.Source);
         XmlNode[] markup = o.Markup;
         if (markup != null)
         {
             for (int i = 0; i < markup.Length; i++)
             {
                 XmlNode node = markup[i];
                 if (node is XmlElement)
                 {
                     XmlElement element = (XmlElement) node;
                     if ((element == null) && (element != null))
                     {
                         throw base.CreateInvalidAnyTypeException(element);
                     }
                     base.WriteElementLiteral(element, "", null, false, true);
                 }
                 else if (node != null)
                 {
                     node.WriteTo(base.Writer);
                 }
                 else if (node != null)
                 {
                     throw base.CreateUnknownTypeException(node);
                 }
             }
         }
         base.WriteEndElement(o);
     }
 }
Example #5
0
        /// <summary>
        /// Load the MIF data from a .NET XmlSchemaAnnotation object
        /// </summary>
        /// <param name="annotation">The .NET XmlSchemaAnnotation object to load the MIF data from</param>
        public void Load(System.Xml.Schema.XmlSchemaAppInfo annotation)
        {
            // Attempt to load
            XmlNode mifAttributeNode = null;

            foreach (XmlNode nd in annotation.Markup)
            {
                if ((nd.LocalName == "attribute" || nd.LocalName == "class" || nd.LocalName == "targetConnection") && nd.NamespaceURI == "urn:hl7-org:v3/mif")
                {
                    mifAttributeNode = nd;
                }
            }

            // Mif attribute found?
            if (mifAttributeNode == null)
            {
                return;
            }

            if (mifAttributeNode.LocalName == "attribute" || mifAttributeNode.LocalName == "targetConnection") // Attribute style MIF
            {
                this.conformance = mifAttributeNode.Attributes["conformance"] != null ? (MifConformance)Enum.Parse(typeof(MifConformance), mifAttributeNode.Attributes["conformance"].Value) : MifConformance.O;
                if (mifAttributeNode.Attributes["isMandatory"] != null && mifAttributeNode.Attributes["isMandatory"].Value == "true")
                {
                    this.conformance = MifConformance.M;
                }
            }

            // Process child elements
            if (mifAttributeNode.SelectSingleNode("//*[local-name() = 'businessName']/@name") != null)
            {
                businessName = mifAttributeNode.SelectSingleNode("//*[local-name() = 'businessName']/@name").Value.Replace("*", "");
                if (businessName.IndexOf(":") > -1)
                {
                    businessName = businessName.Substring(businessName.IndexOf(":") + 1);
                }
            }

            // Definition
            if (mifAttributeNode.SelectSingleNode("//*[local-name() = 'definition']") != null)
            {
                this.documentation = mifAttributeNode.SelectSingleNode("//*[local-name() = 'annotations']/*[local-name() = 'definition']").InnerText;
            }
        }
Example #6
0
        //<annotation
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (appinfo | documentation)*
        //</annotation>
        internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAnnotation.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            annotation.LineNumber   = reader.LineNumber;
            annotation.LinePosition = reader.LinePosition;
            annotation.SourceUri    = reader.BaseURI;

            //Read Attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    annotation.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for annotation", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, annotation);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(annotation);
            }

            //Content: (appinfo | documentation)*
            bool   skip        = false;
            string expectedEnd = null;

            while (!reader.EOF)
            {
                if (skip)
                {
                    skip = false;
                }
                else
                {
                    reader.ReadNextElement();
                }

                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    bool   end      = true;
                    string expected = xmlname;
                    if (expectedEnd != null)
                    {
                        expected    = expectedEnd;
                        expectedEnd = null;
                        end         = false;
                    }
                    if (reader.LocalName != expected)
                    {
                        error(h, "Should not happen :2: XmlSchemaAnnotation.Read, name=" + reader.Name + ",expected=" + expected, null);
                    }
                    if (end)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (reader.LocalName == "appinfo")
                {
                    XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader, h, out skip);
                    if (appinfo != null)
                    {
                        annotation.items.Add(appinfo);
                    }
                    continue;
                }
                if (reader.LocalName == "documentation")
                {
                    XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader, h, out skip);
                    if (documentation != null)
                    {
                        annotation.items.Add(documentation);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(annotation);
        }
 private void AddXmlnsAnnotation(XmlSchemaComplexType type, string xmlnsMemberName)
 {
     XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
     XmlSchemaAppInfo item = new XmlSchemaAppInfo();
     XmlDocument document = new XmlDocument();
     XmlElement element = document.CreateElement("keepNamespaceDeclarations");
     if (xmlnsMemberName != null)
     {
         element.InsertBefore(document.CreateTextNode(xmlnsMemberName), null);
     }
     item.Markup = new XmlNode[] { element };
     annotation.Items.Add(item);
     type.Annotation = annotation;
 }
Example #8
0
        /// <summary>
        /// Creates the an xml schema for a complex type. This method automatically takes care of
        /// any base classes that must be added.
        /// <para />
        /// This method already adds the <see cref="XmlSchemaComplexType" /> to the <see cref="XmlSchemaSet" />.
        /// </summary>
        /// <param name="type">The type to create the complex schema for.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="schemaSet">The schema set.</param>
        /// <param name="serializationManager">The serialization manager.</param>
        /// <param name="generateFlatSchema">A value indicating whether the schema should be generated as flat schema.</param>
        /// <returns>The complex schema for the specified type.</returns>
        private static XmlSchemaComplexType CreateSchemaComplexType(Type type, XmlSchema schema, XmlSchemaSet schemaSet, ISerializationManager serializationManager, bool generateFlatSchema)
        {
            // Determine name, which is complex in generic types
            string typeName = GetTypeNameForSchema(type);

            // First, add the type, otherwise we might get into a stackoverflow when using generic base types
            // <xs:complexType>
            var modelBaseType = new XmlSchemaComplexType();
            modelBaseType.Name = typeName;
            modelBaseType.IsMixed = false;

            schema.Items.Add(modelBaseType);

            var propertiesSequence = GetPropertiesSequence(type, schema, schemaSet, serializationManager);

            // If flat, don't generate base classes, just the type itself
            if (generateFlatSchema)
            {
                modelBaseType.Particle = propertiesSequence;
                return modelBaseType;
            }

            if (type.IsGenericType)
            {
                var genericComplexType = new XmlSchemaComplexType();
                genericComplexType.Name = typeName;

                // <xs:annotation>
                var annotation = new XmlSchemaAnnotation();

                // <xs:appinfo>
                var appInfo = new XmlSchemaAppInfo();

                //<GenericType xmlns="http://schemas.microsoft.com/2003/10/Serialization/" Name="DataContractBaseOf{0}{#}" Namespace="http://schemas.datacontract.org/2004/07/STC">
                //  <GenericParameter Name="ProfileDateRange2" Namespace="http://schemas.datacontract.org/2004/07/STC.Meter.ProfileData"/>
                //</GenericType>
                var genericTypeElement = new XElement("GenericType");
                genericTypeElement.Add(new XAttribute("Name", string.Format("{0}Of{{0}}{{#}}", typeName)));
                genericTypeElement.Add(new XAttribute("Namespace", GetTypeNamespaceForSchema(type)));

                foreach (var genericArgument in type.GetGenericArgumentsEx())
                {
                    var genericArgumentQualifiedName = AddTypeToSchemaSet(genericArgument, schemaSet, serializationManager);
                    var genericArgumentElement = new XElement("GenericParameter");
                    genericArgumentElement.Add(new XAttribute("Name", genericArgumentQualifiedName.Name));
                    genericArgumentElement.Add(new XAttribute("Namespace", genericArgumentQualifiedName.Namespace));
                    genericTypeElement.Add(genericArgumentElement);
                }

                var conversionDoc = new XmlDocument();
                appInfo.Markup = new XmlNode[] { conversionDoc.CreateTextNode(genericTypeElement.ToString()) };

                annotation.Items.Add(appInfo);
            }

            var baseTypeQualifiedName = AddTypeToSchemaSet(type.BaseType, schemaSet, serializationManager);
            if (baseTypeQualifiedName != null)
            {
                // <xs:extensions base="address">
                var complexContentExtension = new XmlSchemaComplexContentExtension();
                complexContentExtension.BaseTypeName = baseTypeQualifiedName;
                complexContentExtension.Particle = propertiesSequence;

                // <xs:complexContent>
                var complexContent = new XmlSchemaComplexContent();
                complexContent.Content = complexContentExtension;

                modelBaseType.ContentModel = complexContent;
            }

            return modelBaseType;
        }
Example #9
0
        void AddXmlnsAnnotation(XmlSchemaComplexType type, string xmlnsMemberName) {
            XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
            XmlSchemaAppInfo appinfo = new XmlSchemaAppInfo();

            XmlDocument d = new XmlDocument();
            XmlElement e = d.CreateElement("keepNamespaceDeclarations");
            if (xmlnsMemberName != null)
                e.InsertBefore(d.CreateTextNode(xmlnsMemberName), null);
            appinfo.Markup = new XmlNode[] {e};
            annotation.Items.Add(appinfo);
            type.Annotation = annotation;
        }
Example #10
0
        private static string ProcessAppInfo(XmlSchemaAppInfo schemaAppInfo)
        {
            StringBuilder result = new StringBuilder();

            if (schemaAppInfo == null)
                return result.ToString();

            if (! string.IsNullOrEmpty(schemaAppInfo.Source))
            {
                result.AppendLine(schemaAppInfo.Source.Trim());
            }

            List<string> parentRefs = new List<string>(); // list of parents under which this type can be nested

            foreach (XmlNode node in schemaAppInfo.Markup)
            {
                switch (node.Name)
                {
                    case "xse:parent":
                        parentRefs.Add(node.Attributes["ref"].Value);
                        break;
                    default:
                        result.AppendLine(string.Format("Unsupported appinfo node: {0}", node.Name));
                        break;
                }
            }

            if (parentRefs.Count > 0)
            {
                result.AppendLine(string.Format("May be nested under \\b {0}.", string.Join(", \\b ", parentRefs.ToArray())));
            }

            return result.ToString();
        }
 private static XmlSchemaAnnotation GetSchemaAnnotation(params System.Xml.XmlNode[] nodes)
 {
     if ((nodes == null) || (nodes.Length == 0))
     {
         return null;
     }
     bool flag = false;
     for (int i = 0; i < nodes.Length; i++)
     {
         if (nodes[i] != null)
         {
             flag = true;
             break;
         }
     }
     if (!flag)
     {
         return null;
     }
     XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
     XmlSchemaAppInfo item = new XmlSchemaAppInfo();
     annotation.Items.Add(item);
     item.Markup = nodes;
     return annotation;
 }
Example #12
0
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
Example #13
0
		internal void ExportDictionaryContractType (CollectionDataContractAttribute attr, SerializationMap map, Type dicType)
		{
			var type = map.RuntimeType;
			var qname = map.XmlName;

			var typeArgs = dicType.IsGenericType ? dicType.GetGenericArguments () : null;
			var keyType = typeArgs != null ? typeArgs [0] : typeof (object);
			var valueType = typeArgs != null ? typeArgs [1] : typeof (object);
			ExportCore (keyType, false);
			ExportCore (valueType, false);

			string keyName = "Key", valueName = "Value";
			if (attr != null) {
				keyName = attr.KeyName ?? keyName;
				valueName = attr.ValueName ?? valueName;
			}
			string itemName = attr != null && attr.ItemName != null ? attr.ItemName : "KeyValueOf" + keyName + valueName;

			var ct = CreateComplexType (qname, type);
			var appInfo = new XmlSchemaAppInfo ();
			var node = new XmlDocument ().CreateElement ("IsDictionary", KnownTypeCollection.MSSimpleNamespace);
			node.InnerText = "true";
			appInfo.Markup = new XmlNode [] { node };
			ct.Annotation = new XmlSchemaAnnotation ();
			ct.Annotation.Items.Add (appInfo);

			var seq = new XmlSchemaSequence ();
			ct.Particle = seq;
			var el = new XmlSchemaElement () { Name = itemName, MinOccurs = 0, MaxOccursString = "unbounded" };
			seq.Items.Add (el);

			var dictType = new XmlSchemaComplexType ();
			el.SchemaType = dictType;
			var dictSeq = new XmlSchemaSequence ();
			dictType.Particle = dictSeq;
			dictSeq.Items.Add (new XmlSchemaElement () { Name = keyName, SchemaTypeName = GetSchemaTypeName (keyType), IsNillable = true });
			dictSeq.Items.Add (new XmlSchemaElement () { Name = valueName, SchemaTypeName = GetSchemaTypeName (valueType), IsNillable = true });
		}
Example #14
0
        static XmlSchemaAnnotation GetSchemaAnnotation(params XmlNode[] nodes)
        {
            if (nodes == null || nodes.Length == 0)
                return null;
            bool hasAnnotation = false;
            for (int i = 0; i < nodes.Length; i++)
                if (nodes[i] != null)
                {
                    hasAnnotation = true;
                    break;
                }
            if (!hasAnnotation)
                return null;

            XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
            XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
            annotation.Items.Add(appInfo);
            appInfo.Markup = nodes;
            return annotation;
        }
 XmlSchemaAnnotation GetSchemaAnnotation(XmlQualifiedName annotationQualifiedName, string innerText, XmlSchema schema)
 {
     XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
     XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
     XmlElement annotationElement = GetAnnotationMarkup(annotationQualifiedName, innerText, schema);
     appInfo.Markup = new XmlNode[1] { annotationElement };
     annotation.Items.Add(appInfo);
     return annotation;
 }
 protected virtual void Visit(XmlSchemaAppInfo appInfo)
 {
 }
Example #17
0
        /// <summary>
        /// Create an element
        /// </summary>
        private XmlSchemaElement CreateElement(Property property, List<TypeReference> genericParameters, string prefix, List<String> includedModels, List<TypeReference> additionalCompileTargets)
        {
            // Return value
            XmlSchemaElement retVal = new XmlSchemaElement()
            {
                Name = property.Name,
                MaxOccursString = property.MaxOccurs == "*" ? "unbounded" : property.MaxOccurs,
                MinOccursString = property.MinOccurs
            };

            TypeReference propertyType = property.Type;
            List<String> collectionTypes = new List<string>() { "LIST","SET","DSET","BAG" };
            
            // Is the property type a collection
            if (property.MaxOccurs != "0" && collectionTypes.Contains(propertyType.CoreDatatypeName) && 
                propertyType.GenericSupplier != null &&
                propertyType.GenericSupplier.Count >0)
                propertyType = propertyType.GenericSupplier[0]; // It is, so we replace with the inner

            
            // Add appinfo for the collapsing needed
            if (property.Annotations != null && property.Annotations.Count > 0)
            {
                if (retVal.Annotation == null) retVal.Annotation = new XmlSchemaAnnotation();
                XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
                XmlDocument appInfoDocument = new XmlDocument();
                appInfoDocument.AppendChild(appInfoDocument.CreateElement("annotations","http://marc.mohawkcollege.ca/hi"));
                foreach (Annotation annot in property.Annotations)
                {
                    XmlNode node = appInfoDocument.DocumentElement.AppendChild(appInfoDocument.CreateElement(annot.GetType().Name, "http://marc.mohawkcollege.ca/hi"));
                    node.InnerText = annot.ToString();
                    
                }
                appInfo.Markup = new XmlNode[] { appInfoDocument.DocumentElement };
                retVal.Annotation.Items.Add(appInfo);
            }

            // Generate the generic type parameter that has been bound upstream?
            if (property.Container is Class && (property.Container as Class).TypeParameters != null && property.Type.Name != null &&
                (property.Container as Class).TypeParameters.Find(o => o.ParameterName == property.Type.Name) != null)
            {
                // Get the current type
                Class containerClass = property.Container as Class;

                // Determine the type order of the generic parameter
                int order = containerClass.TypeParameters.FindIndex(o => o.ParameterName == property.Type.CoreDatatypeName);

                // Alternative traversal name usually happens on a generic
                if (property.AlternateTraversalNames != null && property.AlternateTraversalNames.Count > 0)
                {
                    MohawkCollege.EHR.gpmr.COR.Property.AlternateTraversalData name = property.AlternateTraversalNames.Find(o => o.CaseWhen.Name == genericParameters[order].Name &&
                                                                                        (o.InteractionOwner.Name == prefix || prefix==null));
                    if (name.TraversalName != null) retVal.Name = name.TraversalName;
                }

                // Now set the reference to the generated type
                if (prefix != null && genericParameters != null && genericParameters[order].GenericSupplier != null &&
                    genericParameters[order].GenericSupplier.Count > 0) // Prefix is here
                    retVal.SchemaTypeName = new XmlQualifiedName(String.Format("{0}.{1}", prefix, genericParameters[order].Name), targetNs);
                else if(genericParameters != null)
                {
                    // TODO: Validate this works
                    if (includedModels != null && genericParameters[order].Class != null && !includedModels.Contains(genericParameters[order].Class.ContainerName))
                        includedModels.Add(genericParameters[order].Class.ContainerName);
                    retVal.SchemaTypeName = new XmlQualifiedName(genericParameters[order].Name, targetNs);
                }
                else
                    Trace.WriteLine(String.Format("Generic parameters are not specified '{0}'...", property.Name), "error");
            }
            else if (property.Type.Class != null && property.Type.GenericSupplier != null && property.Type.GenericSupplier.Count > 0) // Other Generic
            {
                // Add this to the list of types that need to be generated
                additionalCompileTargets.Add(property.Type);
                // Now set the reference
                if (prefix != null) // Prefix is here
                    retVal.SchemaTypeName = new XmlQualifiedName(String.Format("{0}.{1}", prefix, property.Type.Name), targetNs);
                else
                {
                    // TODO: Validate this works
                    if (!includedModels.Contains(property.Type.Class.ContainerName))
                        includedModels.Add(property.Type.Class.ContainerName);
                    retVal.SchemaTypeName = new XmlQualifiedName(property.Type.Class.ContainerName, targetNs);
                }
            }
            else if (property.Type.Class != null) // Complex association
            {

                // Attempt to bind to the class

                // Genericized type reference, so we need to generate a new type reference
                if (property.Type.GenericSupplier != null && property.Type.GenericSupplier.Count > 0)
                    ;//TODO: Generate a new type here
                else
                {
                    if (!includedModels.Contains(property.Type.Class.ContainerName))
                        includedModels.Add(property.Type.Class.ContainerName);
                    retVal.SchemaTypeName = new XmlQualifiedName(property.Type.Name, targetNs);
                }
            }
            else if (propertyType.CoreDatatypeName != null) // Data Type
            {
                var dataType = dataTypes.Find(o => o.Name == MakeSchemaFriendlyCoreType(propertyType));
                if (dataType == null)
                {
                    System.Diagnostics.Trace.WriteLine(String.Format("Can't find data type '{0}' in the file '{1}'. Using xs:any...", propertyType.CoreDatatypeName, dataTypesXsd), "warn");
                    retVal.SchemaTypeName = new XmlQualifiedName("anyType", "http://www.w3.org/2001/XMLSchema");
                }
                else
                    retVal.SchemaTypeName = new XmlQualifiedName(dataType.Name, dataType.Namespace);
            }
            else
                System.Diagnostics.Trace.WriteLine(String.Format("Can't bind type '{0}' to element '{1}'. Can't determine type family.", property.Type.Name, property.Name), "warn");

            // Generate property documentation
            if (!Documentation.IsEmpty(property.Documentation))
            {
                if(retVal.Annotation == null) retVal.Annotation = new XmlSchemaAnnotation();

                XmlSchemaDocumentation documentation = new XmlSchemaDocumentation();
                XmlDocument documentationMarkup = new XmlDocument();
                documentationMarkup.LoadXml("<div xmlns=\"http://www.w3.org/1999/xhtml\">" + property.Documentation.ToString() + "</div>");
                documentation.Markup = new List<XmlNode>(documentationMarkup.ChildNodes.Cast<XmlNode>()).ToArray();
                retVal.Annotation.Items.Add(documentation);
            }

            return retVal;
        }
 private XmlSchemaAnnotation GetSchemaAnnotation(XmlQualifiedName annotationQualifiedName, string innerText, XmlSchema schema)
 {
     XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
     XmlSchemaAppInfo item = new XmlSchemaAppInfo();
     XmlElement element = this.GetAnnotationMarkup(annotationQualifiedName, innerText, schema);
     item.Markup = new System.Xml.XmlNode[] { element };
     annotation.Items.Add(item);
     return annotation;
 }
 private void Write7_XmlSchemaAppInfo(XmlSchemaAppInfo o)
 {
     if (o != null)
     {
         this.WriteStartElement("appinfo");
         this.WriteAttribute("source", "", o.Source);
         XmlNode[] markup = o.Markup;
         if (markup != null)
         {
             for (int i = 0; i < markup.Length; i++)
             {
                 XmlNode node = markup[i];
                 this.WriteStartElement("node");
                 this.WriteAttribute("xml", "", node.OuterXml);
             }
         }
         this.WriteEndElement();
     }
 }
        internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnnotation xmlSchemaAnnotation = new XmlSchemaAnnotation();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "annotation")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAnnotation.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaAnnotation.LineNumber   = reader.LineNumber;
            xmlSchemaAnnotation.LinePosition = reader.LinePosition;
            xmlSchemaAnnotation.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaAnnotation.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for annotation", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaAnnotation);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaAnnotation);
            }
            bool   flag = false;
            string text = null;

            while (!reader.EOF)
            {
                if (flag)
                {
                    flag = false;
                }
                else
                {
                    reader.ReadNextElement();
                }
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    bool   flag2 = true;
                    string text2 = "annotation";
                    if (text != null)
                    {
                        text2 = text;
                        text  = null;
                        flag2 = false;
                    }
                    if (reader.LocalName != text2)
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaAnnotation.Read, name=" + reader.Name + ",expected=" + text2, null);
                    }
                    if (flag2)
                    {
                        break;
                    }
                }
                else if (reader.LocalName == "appinfo")
                {
                    XmlSchemaAppInfo xmlSchemaAppInfo = XmlSchemaAppInfo.Read(reader, h, out flag);
                    if (xmlSchemaAppInfo != null)
                    {
                        xmlSchemaAnnotation.items.Add(xmlSchemaAppInfo);
                    }
                }
                else if (reader.LocalName == "documentation")
                {
                    XmlSchemaDocumentation xmlSchemaDocumentation = XmlSchemaDocumentation.Read(reader, h, out flag);
                    if (xmlSchemaDocumentation != null)
                    {
                        xmlSchemaAnnotation.items.Add(xmlSchemaDocumentation);
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaAnnotation);
        }
 void Write7_XmlSchemaAppInfo(XmlSchemaAppInfo o) {
     if ((object)o == null) return;
     WriteStartElement("appinfo");
     
     WriteAttribute("source", "", o.Source);
     XmlNode[] a = (XmlNode[])o.@Markup;
     if (a != null) {
         for (int ia = 0; ia < a.Length; ia++) {
             XmlNode ai = (XmlNode)a[ia];
             WriteStartElement("node");
             WriteAttribute("xml", "", ai.OuterXml);
         }
     }
     WriteEndElement();
 }
Example #22
0
        private static void ApplyAnnotation(XmlSchemaAnnotated annotatedType, DescriptionAttribute[] descriptionAtts,
            ConfigurationPropertyAttribute configProperty, string xmlDocumentation, string typeName, string fullName)
        {
            string standardDesc;

            if (configProperty != null)
            {
                standardDesc = configProperty.IsRequired ? "Required" : "Optional";
                standardDesc += " " + fullName;
                standardDesc += " " +
                                (configProperty.DefaultValue == null || configProperty.DefaultValue.ToString() == "System.Object"
                                    ? string.Empty
                                    : "[" + configProperty.DefaultValue + "]");
            }
            else
            {
                standardDesc = string.Empty;
            }

            var documentation = new XmlSchemaDocumentation();
            if (descriptionAtts.Length > 0)
            {
                documentation.Markup = TextToNodeArray(descriptionAtts[0].Description + " " + standardDesc);
            }
            else if (!String.IsNullOrEmpty(xmlDocumentation))
            {
                // normalise line endings and remove trailing whitespace(s)
                xmlDocumentation = Regex.Replace(xmlDocumentation, @"\s*(\r\n|\n\r|\n|\r)", "\r\n");

                documentation.Markup = TextToNodeArray(xmlDocumentation);
            }
            else
            {
                documentation.Markup = TextToNodeArray(standardDesc);
            }

            //  machine documentation
            var appInfo = new XmlSchemaAppInfo
            {
                Markup = TextToNodeArray(typeName)
            };

            //  add the documentation to the object
            annotatedType.Annotation.Items.Add(documentation);
            annotatedType.Annotation.Items.Add(appInfo);
        }