/// <summary> /// Writes type attribute /// </summary> /// <param name="property">property whose <see cref="Model.TypedElement.Type"/> attribute is being written</param> /// <param name="simpleTypeWriter">writer where simple type definition is written if the type was not /// yet used</param> /// <param name="useOccurs">if set to true, minOccurs and maxOccurs attributes are also written if /// <paramref name="property"/> multipicity is non-default</param> /// <param name="forceOptional">if set to <c>true</c> multiplicity of the attribute is ignored and /// use="optional" is written.</param> public void TypeAttribute(Property property, ref SimpleTypesWriter simpleTypeWriter, bool useOccurs, bool forceOptional) { DataType type = property.Type; if (type == null) { Writer.WriteAttributeString("type", "xs:string"); Log.AddWarning(string.Format(LogMessages.XS_TYPE_TRANSLATED_AS_STRING, type, property.Class, property)); } else { SimpleDataType simpleType = type as SimpleDataType; if (simpleType != null) { if (!string.IsNullOrEmpty(simpleType.DefaultXSDImplementation)) { if (simpleType.Parent != null) { simpleTypeWriter.WriteSimpleDataTypeDeclaration(simpleType); Writer.WriteAttributeString("type", simpleType.Name); } else { Writer.WriteAttributeString("type", NamespacePrefix + ":" + simpleType.DefaultXSDImplementation); } } else { if (type is SimpleDataType) { Writer.WriteAttributeString("type", NamespacePrefix + ":" + type.Name); Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type)); } else { Writer.WriteAttributeString("type", type.Name); Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type)); } } } else { Writer.WriteAttributeString("type", type.ToString()); } } if (!String.IsNullOrEmpty(property.Default)) { Writer.WriteAttributeString("default", property.Default); } if (forceOptional) { Writer.WriteAttributeString("use", "optional"); } else { if (!useOccurs) { if (property.Lower == 0 || property.Lower == null) { Writer.WriteAttributeString("use", "optional"); if (property.Upper > 1) { Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString, property.Class, property)); } } else { if (property.Upper > 1 || property.Lower > 1) { Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString, property.Class, property)); } if (String.IsNullOrEmpty(property.Default)) { Writer.WriteAttributeString("use", "required"); } } } else { MultiplicityAttributes(property.Lower, property.Upper); } } IsEmpty = false; AfterWriteDebug(); }
public void typeAttribute(Property property, XmlElement targetElement, bool useOccurs, bool forceOptional) { DataType type = property.Type; if (type == null) { targetElement.SetAttribute("type", "xs:string"); Log.AddWarning(string.Format(LogMessages.XS_TYPE_TRANSLATED_AS_STRING, type, property.Class, property)); } else { SimpleDataType simpleType = type as SimpleDataType; if (simpleType != null) { if (!string.IsNullOrEmpty(simpleType.DefaultXSDImplementation)) { if (simpleType.Parent != null) { //todo: simpleTypeWriter.WriteSimpleDataTypeDeclaration(simpleType); targetElement.SetAttribute("type", simpleType.Name); } else { targetElement.SetAttribute("type", "xs" + ":" + simpleType.DefaultXSDImplementation); } } else { if (type is SimpleDataType) { targetElement.SetAttribute("type", "xs" + ":" + type.Name); Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type)); } else { targetElement.SetAttribute("type", type.Name); Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type)); } } } else { targetElement.SetAttribute("type", type.ToString()); } } if (!String.IsNullOrEmpty(property.Default)) { targetElement.SetAttribute("default", property.Default); } if (forceOptional) { targetElement.SetAttribute("use", "optional"); } else { if (!useOccurs) { if (property.Lower == 0 || property.Lower == null) { targetElement.SetAttribute("use", "optional"); if (property.Upper > 1) { Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString, property.Class, property)); } } else { if (property.Upper > 1 || property.Lower > 1) { Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString, property.Class, property)); } if (String.IsNullOrEmpty(property.Default)) { targetElement.SetAttribute("use", "required"); } } } else { this.multiplicityAttributes(targetElement, property.Lower, property.Upper); } } }