Welcome to mirror list, hosted at ThFree Co, Russian Federation.

HandlerBase.cs « Common « Data « System « System.Data « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 99945fe78ce8d1107e163d9c94caceb9e1a65cae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//------------------------------------------------------------------------------
// <copyright file="HandlerBase.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">[....]</owner>
//------------------------------------------------------------------------------

namespace System.Data.Common {

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Diagnostics;
    using System.Globalization;
    using System.Xml;

    internal static class HandlerBase {

        static internal void CheckForChildNodes(XmlNode node) {
            if (node.HasChildNodes) {
                throw ADP.ConfigBaseNoChildNodes(node.FirstChild);
            }
        }
        static private void CheckForNonElement(XmlNode node) {
            if (XmlNodeType.Element != node.NodeType) {
                throw ADP.ConfigBaseElementsOnly(node);
            }
        }
        static internal void CheckForUnrecognizedAttributes(XmlNode node) {
            if (0 != node.Attributes.Count) {
                throw ADP.ConfigUnrecognizedAttributes(node);
            }
        }
        
        // skip whitespace and comments, throws if non-element
        static internal bool IsIgnorableAlsoCheckForNonElement(XmlNode node) {
            if ((XmlNodeType.Comment == node.NodeType) || (XmlNodeType.Whitespace == node.NodeType)) {
                return true;
            }
            CheckForNonElement(node);
            return false;
        }

        static internal string RemoveAttribute(XmlNode node, string name, bool required, bool allowEmpty) {
            XmlNode attribute = node.Attributes.RemoveNamedItem(name);
            if (null == attribute) {
                if (required) {
                    throw ADP.ConfigRequiredAttributeMissing(name, node);
                }
                return null;
            }
            string value = attribute.Value;
            if (!allowEmpty && (0 == value.Length)) {
                throw ADP.ConfigRequiredAttributeEmpty(name, node);
            }
            return value;
        }

        static internal DataSet CloneParent(DataSet parentConfig, bool insenstive) {
            if (null == parentConfig) {
                parentConfig = new DataSet(DbProviderFactoriesConfigurationHandler.sectionName);
                parentConfig.CaseSensitive = !insenstive;
                parentConfig.Locale = CultureInfo.InvariantCulture;
            }
            else {
                parentConfig = parentConfig.Copy();
            }
            return parentConfig;
        }
    }
}