ObjectNameResolver.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // System.Data.Configuration.ObjectNameResolver.cs
  3. //
  4. // Authors:
  5. // Konstantin Triger <[email protected]>
  6. //
  7. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.Collections;
  30. using System.Configuration;
  31. using System.Xml;
  32. using System.Text.RegularExpressions;
  33. namespace System.Data.Configuration {
  34. sealed class ObjectNameResolver : IComparable {
  35. string _dbname;
  36. int _priority;
  37. Regex _regex;
  38. public ObjectNameResolver(string dbname, string match, int priority) {
  39. _dbname = dbname;
  40. _regex = new Regex(match, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  41. _priority = priority;
  42. }
  43. public ObjectNameResolver(Regex regex) {
  44. _regex = regex;
  45. _dbname = null;
  46. _priority = int.MaxValue;
  47. }
  48. public string DbName {
  49. get {
  50. return _dbname;
  51. }
  52. }
  53. public static string GetCatalog(Match match) {
  54. return GetCapture(match, "CATALOG");
  55. }
  56. public static string GetSchema(Match match) {
  57. return GetCapture(match, "SCHEMA");
  58. }
  59. public static string GetName(Match match) {
  60. return GetCapture(match, "NAME");
  61. }
  62. public Match Match(string expression) {
  63. return _regex.Match(expression.Trim());
  64. }
  65. static string GetCapture(Match match, string captureName) {
  66. Group g = match.Groups[captureName];
  67. if (!g.Success)
  68. return String.Empty;
  69. return g.Value.Trim();
  70. }
  71. #region IComparable Members
  72. public int CompareTo(object obj) {
  73. // TODO: Add ObjectNameResolver.CompareTo implementation
  74. return _priority.CompareTo(((ObjectNameResolver)obj)._priority);
  75. }
  76. #endregion
  77. }
  78. }