HandlerBase.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. namespace System.Data.Common {
  9. using System;
  10. using System.Collections;
  11. using System.Configuration;
  12. using System.Diagnostics;
  13. using System.Globalization;
  14. using System.Xml;
  15. internal static class HandlerBase {
  16. static internal void CheckForChildNodes(XmlNode node) {
  17. if (node.HasChildNodes) {
  18. throw ADP.ConfigBaseNoChildNodes(node.FirstChild);
  19. }
  20. }
  21. static private void CheckForNonElement(XmlNode node) {
  22. if (XmlNodeType.Element != node.NodeType) {
  23. throw ADP.ConfigBaseElementsOnly(node);
  24. }
  25. }
  26. static internal void CheckForUnrecognizedAttributes(XmlNode node) {
  27. if (0 != node.Attributes.Count) {
  28. throw ADP.ConfigUnrecognizedAttributes(node);
  29. }
  30. }
  31. // skip whitespace and comments, throws if non-element
  32. static internal bool IsIgnorableAlsoCheckForNonElement(XmlNode node) {
  33. if ((XmlNodeType.Comment == node.NodeType) || (XmlNodeType.Whitespace == node.NodeType)) {
  34. return true;
  35. }
  36. CheckForNonElement(node);
  37. return false;
  38. }
  39. static internal string RemoveAttribute(XmlNode node, string name, bool required, bool allowEmpty) {
  40. XmlNode attribute = node.Attributes.RemoveNamedItem(name);
  41. if (null == attribute) {
  42. if (required) {
  43. throw ADP.ConfigRequiredAttributeMissing(name, node);
  44. }
  45. return null;
  46. }
  47. string value = attribute.Value;
  48. if (!allowEmpty && (0 == value.Length)) {
  49. throw ADP.ConfigRequiredAttributeEmpty(name, node);
  50. }
  51. return value;
  52. }
  53. static internal DataSet CloneParent(DataSet parentConfig, bool insenstive) {
  54. if (null == parentConfig) {
  55. parentConfig = new DataSet(DbProviderFactoriesConfigurationHandler.sectionName);
  56. parentConfig.CaseSensitive = !insenstive;
  57. parentConfig.Locale = CultureInfo.InvariantCulture;
  58. }
  59. else {
  60. parentConfig = parentConfig.Copy();
  61. }
  62. return parentConfig;
  63. }
  64. }
  65. }