Example #1
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, NestedClass element, global::System.Xml.XmlWriter writer)
		{
			// NestedClassHasProperties
			global::System.Collections.ObjectModel.ReadOnlyCollection<NestedClassHasProperties> allNestedClassHasPropertiesInstances = NestedClassHasProperties.GetLinksToProperties(element);
			if (!serializationContext.Result.Failed && allNestedClassHasPropertiesInstances.Count > 0)
			{
				writer.WriteStartElement("properties");
				global::System.Type typeofNestedClassHasProperties = typeof(NestedClassHasProperties);
				foreach (NestedClassHasProperties eachNestedClassHasPropertiesInstance in allNestedClassHasPropertiesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachNestedClassHasPropertiesInstance.GetType() != typeofNestedClassHasProperties)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachNestedClassHasPropertiesInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachNestedClassHasPropertiesInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachNestedClassHasPropertiesInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachNestedClassHasPropertiesInstance.Property;
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");			
						targetSerializer.Write(serializationContext, targetElement, writer);
					}
				}
				writer.WriteEndElement();
			}
	
			// NestedClassReferencesModelClasses
			global::System.Collections.ObjectModel.ReadOnlyCollection<NestedClassReferencesModelClasses> allNestedClassReferencesModelClassesInstances = NestedClassReferencesModelClasses.GetLinksToModelClasses(element);
			if (!serializationContext.Result.Failed && allNestedClassReferencesModelClassesInstances.Count > 0)
			{
				writer.WriteStartElement("modelClasses");
				foreach (NestedClassReferencesModelClasses eachNestedClassReferencesModelClassesInstance in allNestedClassReferencesModelClassesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachNestedClassReferencesModelClassesInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachNestedClassReferencesModelClassesInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachNestedClassReferencesModelClassesInstance, writer);
				}
				writer.WriteEndElement();
			}
	
		}
Example #2
0
		/// <summary>
		/// Reads all instances of relationship NestedClassHasProperties.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be
		/// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the
		/// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens).
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory NestedClass instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadNestedClassHasPropertiesInstances(DslModeling::SerializationContext serializationContext, NestedClass element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newModelPropertyOfNestedClassHasPropertiesSerializer = serializationContext.Directory.GetSerializer(ModelProperty.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newModelPropertyOfNestedClassHasPropertiesSerializer != null, "Cannot find serializer for ModelProperty!");
				ModelProperty newModelPropertyOfNestedClassHasProperties = newModelPropertyOfNestedClassHasPropertiesSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as ModelProperty;
				if (newModelPropertyOfNestedClassHasProperties != null)
				{
					element.Properties.Add(newModelPropertyOfNestedClassHasProperties);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newModelPropertyOfNestedClassHasProperties.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newModelPropertyOfNestedClassHasProperties.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newModelPropertyOfNestedClassHasProperties, reader);
				}
				else
				{
					global::System.Type typeofNestedClassHasProperties = typeof(NestedClassHasProperties);
					DslModeling::DomainRelationshipXmlSerializer newNestedClassHasPropertiesSerializer = serializationContext.Directory.GetSerializer(NestedClassHasProperties.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newNestedClassHasPropertiesSerializer != null, "Cannot find serializer for NestedClassHasProperties!");
					NestedClassHasProperties newNestedClassHasProperties = newNestedClassHasPropertiesSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as NestedClassHasProperties;
					if (newNestedClassHasProperties != null)
					{
						if (newNestedClassHasProperties.GetType() == typeofNestedClassHasProperties)
						{	// The relationship should be serialized in short-form.
							ActiveWriterSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(NestedClassHasProperties));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newNestedClassHasProperties, NestedClassHasProperties.NestedClassDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newNestedClassHasProperties.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newNestedClassHasProperties.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newNestedClassHasProperties, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Example #3
0
		private static void ReadNestedClassReferencesModelClassesInstances(DslModeling::SerializationContext serializationContext, NestedClass element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newNestedClassReferencesModelClassesSerializer = serializationContext.Directory.GetSerializer(NestedClassReferencesModelClasses.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newNestedClassReferencesModelClassesSerializer != null, "Cannot find serializer for NestedClassReferencesModelClasses!");
				NestedClassReferencesModelClasses newNestedClassReferencesModelClasses = newNestedClassReferencesModelClassesSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as NestedClassReferencesModelClasses;
				if (newNestedClassReferencesModelClasses != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newNestedClassReferencesModelClasses, NestedClassReferencesModelClasses.NestedClassDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newNestedClassReferencesModelClasses.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newNestedClassReferencesModelClasses.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newNestedClassReferencesModelClasses, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newModelClassMonikerOfNestedClassReferencesModelClassesSerializer = serializationContext.Directory.GetSerializer(ModelClass.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newModelClassMonikerOfNestedClassReferencesModelClassesSerializer != null, "Cannot find serializer for ModelClass!");
					DslModeling::Moniker newModelClassMonikerOfNestedClassReferencesModelClasses = newModelClassMonikerOfNestedClassReferencesModelClassesSerializer.TryCreateMonikerInstance(serializationContext, reader, element, NestedClassReferencesModelClasses.DomainClassId, element.Partition);
					if (newModelClassMonikerOfNestedClassReferencesModelClasses != null)
					{
						ActiveWriterSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(NestedClassReferencesModelClasses));
						new NestedClassReferencesModelClasses(element.Partition, new DslModeling::RoleAssignment(NestedClassReferencesModelClasses.NestedClassDomainRoleId, element), new DslModeling::RoleAssignment(NestedClassReferencesModelClasses.ModelClassDomainRoleId, newModelClassMonikerOfNestedClassReferencesModelClasses));
						DslModeling::SerializationUtilities.Skip(reader);	// Moniker contains no child XML elements, so just skip.
					}
					else
					{	// Unknown element, skip.
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Example #4
0
		/// <summary>
		/// This method deserializes all child model elements.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first child XML element to deserialized.
		/// This method will read as many child elements as it can. It returns under three circumstances:
		/// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the 
		///    open tag of the unknown element. This implies that if the first child XML element is unknown, this method 
		///    should return immediately and do nothing.
		/// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element.
		/// 3) EOF.
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		/// <param name="element">In-memory NestedClass instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, NestedClass element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "properties":	// Relationship "NestedClassHasProperties"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <properties>
							ReadNestedClassHasPropertiesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </properties>
						}
						break;
					case "modelClasses":	// Relationship "NestedClassReferencesModelClasses"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <modelClasses>
							ReadNestedClassReferencesModelClassesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </modelClasses>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}