6edbe3939c23c0357ea8bf421dfd3e1fe8057cf9
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / EntityModel / SchemaObjectModel / Documentation.cs
1 //---------------------------------------------------------------------
2 // <copyright file="Documentation.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 namespace System.Data.EntityModel.SchemaObjectModel
11 {
12     using System.Data.Common.Utils;
13     using System.Data.Metadata.Edm;
14     using System.Xml;
15
16     /// <summary>
17     /// Summary description for Documentation.
18     /// </summary>
19     internal sealed class DocumentationElement: SchemaElement
20     {
21         #region Instance Fields
22         Documentation _metdataDocumentation = new Documentation();
23         #endregion
24
25
26         #region Public Methods
27         /// <summary>
28         /// 
29         /// </summary>
30         /// <param name="parentElement"></param>
31         public DocumentationElement(SchemaElement parentElement)
32         :   base(parentElement)
33         {
34         }
35         #endregion
36
37         #region Public Properties
38
39         /// <summary>
40         /// Returns the wrapped metaDocumentation instance
41         /// </summary>
42         public Documentation MetadataDocumentation
43         {
44             get
45             {
46                 _metdataDocumentation.SetReadOnly();
47                 return _metdataDocumentation;
48             }
49         }
50
51
52         #endregion
53
54         #region Protected Properties
55         protected override bool HandleElement(XmlReader reader)
56         {
57             if (base.HandleElement(reader))
58             {
59                 return true;
60             }
61             else if (CanHandleElement(reader, XmlConstants.Summary))
62             {
63                 HandleSummaryElement(reader);
64                 return true;
65             }
66             else if (CanHandleElement(reader, XmlConstants.LongDescription))
67             {
68                 HandleLongDescriptionElement(reader);
69                 return true;
70             }
71             return false;
72         }
73         #endregion
74
75         #region Private Methods
76
77         protected override bool HandleText(XmlReader reader)
78         {
79             string text = reader.Value;
80             if (!StringUtil.IsNullOrEmptyOrWhiteSpace(text))
81             {
82                 AddError(ErrorCode.UnexpectedXmlElement, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidDocumentationBothTextAndStructure);
83             }
84             return true;
85         }
86
87         /// <summary>
88         /// 
89         /// </summary>
90         /// <param name="reader"></param>
91         private void HandleSummaryElement(XmlReader reader)
92         {
93             TextElement text = new TextElement(this);
94
95             text.Parse(reader);
96
97             _metdataDocumentation.Summary = text.Value;
98         }
99
100         /// <summary>
101         /// 
102         /// </summary>
103         /// <param name="reader"></param>
104         private void HandleLongDescriptionElement(XmlReader reader)
105         {
106
107             TextElement text = new TextElement(this);
108
109             text.Parse(reader);
110
111             _metdataDocumentation.LongDescription = text.Value;
112         }
113         #endregion
114     }
115 }