Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data / System / Data / Common / HandlerBase.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="HandlerBase.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8
9 namespace System.Data.Common {
10
11     using System;
12     using System.Collections;
13     using System.Configuration;
14     using System.Diagnostics;
15     using System.Globalization;
16     using System.Xml;
17
18     internal static class HandlerBase {
19
20         static internal void CheckForChildNodes(XmlNode node) {
21             if (node.HasChildNodes) {
22                 throw ADP.ConfigBaseNoChildNodes(node.FirstChild);
23             }
24         }
25         static private void CheckForNonElement(XmlNode node) {
26             if (XmlNodeType.Element != node.NodeType) {
27                 throw ADP.ConfigBaseElementsOnly(node);
28             }
29         }
30         static internal void CheckForUnrecognizedAttributes(XmlNode node) {
31             if (0 != node.Attributes.Count) {
32                 throw ADP.ConfigUnrecognizedAttributes(node);
33             }
34         }
35         
36         // skip whitespace and comments, throws if non-element
37         static internal bool IsIgnorableAlsoCheckForNonElement(XmlNode node) {
38             if ((XmlNodeType.Comment == node.NodeType) || (XmlNodeType.Whitespace == node.NodeType)) {
39                 return true;
40             }
41             CheckForNonElement(node);
42             return false;
43         }
44
45         static internal string RemoveAttribute(XmlNode node, string name, bool required, bool allowEmpty) {
46             XmlNode attribute = node.Attributes.RemoveNamedItem(name);
47             if (null == attribute) {
48                 if (required) {
49                     throw ADP.ConfigRequiredAttributeMissing(name, node);
50                 }
51                 return null;
52             }
53             string value = attribute.Value;
54             if (!allowEmpty && (0 == value.Length)) {
55                 throw ADP.ConfigRequiredAttributeEmpty(name, node);
56             }
57             return value;
58         }
59
60         static internal DataSet CloneParent(DataSet parentConfig, bool insenstive) {
61             if (null == parentConfig) {
62                 parentConfig = new DataSet(DbProviderFactoriesConfigurationHandler.sectionName);
63                 parentConfig.CaseSensitive = !insenstive;
64                 parentConfig.Locale = CultureInfo.InvariantCulture;
65             }
66             else {
67                 parentConfig = parentConfig.Copy();
68             }
69             return parentConfig;
70         }
71     }
72 }