Пример #1
0
        /// <summary>
        /// Creates the writer whose contents will be contained in result returned by <see cref="GetResult"/>.
        /// </summary>
        /// <param name="ghostWriter"></param>
        /// <returns>Created writer</returns>
        public XmlSchemaWriter CreateGlobalWriter(bool ghostWriter)
        {
            XmlSchemaWriter classWriter = CreateWriter();

            classWriter.IsGhostWriter = ghostWriter;
            createdTreeDeclarations.Add(classWriter);
            return(classWriter);
        }
Пример #2
0
 /// <summary>
 /// Appends content of another XmlSchemaWriter.
 /// </summary>
 /// <param name="writer"></param>
 public void AppendContent(XmlSchemaWriter writer)
 {
     writer.EndElement();             // wrap
     // this is important!
     writer.Writer.Flush();
     Writer.AppendXMLFragment(writer._sb.ToString(), "wrap");
     IsEmpty = false;
     AfterWriteDebug();
     writer.Writer.Close();
 }
Пример #3
0
        /// <summary>
        /// Creates empty XmlSchemaWriter.
        /// </summary>
        /// <param name="sb">Underlying stringbuilder where writer will write</param>
        public XmlSchemaWriter CreateWriter(StringBuilder sb)
        {
            XmlWriter       writer          = XmlWriter.Create(sb, writerSettings);
            XmlSchemaWriter xmlSchemaWriter = new XmlSchemaWriter(writer, sb, Log);

            // ReSharper disable PossibleNullReferenceException
            writer.WriteStartElement("wrap");
            // ReSharper restore PossibleNullReferenceException
            writer.WriteAttributeString("xmlns", "xs", null, "http://www.w3.org/2001/XMLSchema");
            return(xmlSchemaWriter);
        }
Пример #4
0
        /// <summary>
        /// Reset's the factory for new translation
        /// </summary>
        public void Initialize()
        {
            if (createdTreeDeclarations == null)
            {
                createdTreeDeclarations = new List <XmlSchemaWriter>();
            }
            else
            {
                createdTreeDeclarations.Clear();
            }

            _sbGlobalDeclarations = new StringBuilder();
            globalDeclarations    = CreateWriter(_sbGlobalDeclarations);

            _sbSimpleTypes = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(_sbSimpleTypes, writerSettings);

            simpleTypesDeclarations = new SimpleTypesWriter(writer, _sbSimpleTypes, Log);
            // ReSharper disable PossibleNullReferenceException
            writer.WriteStartElement("wrap");
            // ReSharper restore PossibleNullReferenceException
            writer.WriteAttributeString("xmlns", "xs", null, "http://www.w3.org/2001/XMLSchema");
        }
Пример #5
0
        /// <summary>
        /// Gets the result
        /// (<see cref="globalDeclarations"/> + all writers created with <see cref="CreateGlobalWriter"/> + <see cref="simpleTypesDeclarations"/>)
        /// wrapped in schema element.
        /// </summary>
        /// <returns>resulting xml schema</returns>
        public string GetResult(string projectNamespace, PSMDiagram diagram)
        {
            StringBuilder   _sbResult = new StringBuilder();
            XmlWriter       wrResult  = XmlWriter.Create(_sbResult, resultSettings);
            XmlSchemaWriter w         = new XmlSchemaWriter(wrResult, _sbResult, Log);

            wrResult.WriteStartDocument();
            w.Schema();
            if (!projectNamespace.EndsWith("/"))
            {
                projectNamespace = projectNamespace + "/";
            }
            wrResult.WriteAttributeString("xmlns", projectNamespace);
            wrResult.Flush();
            _sbResult.AppendLine();
            wrResult.WriteAttributeString("elementFormDefault", "qualified");
            wrResult.Flush();
            _sbResult.AppendLine();
            if (!String.IsNullOrEmpty(diagram.TargetNamespace))
            {
                wrResult.WriteAttributeString("targetNamespace", diagram.TargetNamespace);
            }
            else
            {
                wrResult.WriteAttributeString("targetNamespace", projectNamespace);
            }
            wrResult.Flush();
            _sbResult.AppendLine();
            foreach (PSMDiagramReference psmDiagramReference in diagram.DiagramReferences)
            {
                if (!String.IsNullOrEmpty(psmDiagramReference.Namespace))
                {
                    // writer.WriteAttributeString("xmlns", "bk", null, "urn:book");
                    // Write the xmlns:bk="urn:book" namespace declaration
                    // chci xmlns:per="http://www.person.org"
                    wrResult.WriteAttributeString("xmlns", psmDiagramReference.NamespacePrefix, null, psmDiagramReference.Namespace);
                    wrResult.Flush();
                    _sbResult.AppendLine();
                }
            }

            if (globalDeclarations.IsEmpty)
            {
                Log.AddWarning(LogMessages.XS_NO_ROOT);
            }
            else
            {
                w.AppendContent(globalDeclarations);
                wrResult.Flush();
                _sbResult.AppendLine();
            }
            foreach (XmlSchemaWriter writer in createdTreeDeclarations)
            {
                if (!writer.IsEmpty && !writer.IsGhostWriter)
                {
                    w.AppendContent(writer);
                    w.Writer.Flush();
                    _sbResult.AppendLine();
                }
            }
            if (!simpleTypesDeclarations.IsEmpty)
            {
                w.AppendContent(simpleTypesDeclarations);
            }
            globalDeclarations.Writer.Close();
            wrResult.WriteEndElement();             // schema
            wrResult.Close();
            return(_sbResult.ToString());
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TranslationContext"/> class.
 /// </summary>
 /// <param name="treeDeclarations">The tree declarations writer.</param>
 /// <param name="composedContent">The composed content writer.</param>
 /// <param name="composedAttributes">The composed attributes writer.</param>
 public TranslationContext(XmlSchemaWriter treeDeclarations, XmlSchemaWriter composedContent, XmlSchemaWriter composedAttributes)
 {
     this.TreeDeclarations   = treeDeclarations;
     this.ComposedContent    = composedContent;
     this.ComposedAttributes = composedAttributes;
 }