2 // System.Data.Configuration.ObjectNameResolver.cs
5 // Konstantin Triger <kostat@mainsoft.com>
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
\r
32 using System.Configuration;
\r
34 using System.Text.RegularExpressions;
\r
36 namespace System.Data.Configuration {
\r
37 sealed class ObjectNameResolver : IComparable {
\r
42 public ObjectNameResolver(string dbname, string match, int priority) {
\r
44 _regex = new Regex(match, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
46 _priority = priority;
\r
49 public ObjectNameResolver(Regex regex) {
\r
52 _priority = int.MaxValue;
\r
55 public string DbName {
\r
61 public static string GetCatalog(Match match) {
\r
62 return GetCapture(match, "CATALOG");
\r
65 public static string GetSchema(Match match) {
\r
66 return GetCapture(match, "SCHEMA");
\r
69 public static string GetName(Match match) {
\r
70 return GetCapture(match, "NAME");
\r
73 public Match Match(string expression) {
\r
74 return _regex.Match(expression.Trim());
\r
77 static string GetCapture(Match match, string captureName) {
\r
78 Group g = match.Groups[captureName];
\r
80 return String.Empty;
\r
82 return g.Value.Trim();
\r
85 #region IComparable Members
\r
87 public int CompareTo(object obj) {
\r
88 // TODO: Add ObjectNameResolver.CompareTo implementation
\r
89 return _priority.CompareTo(((ObjectNameResolver)obj)._priority);
\r