[Mono-list] ProviderSectionHandler revisited

Marco Canini marco.canini@fastwebnet.it
Fri, 24 Oct 2003 15:47:52 +0200


This is a multi-part message in MIME format.
--------------040600060800040208080407
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Ok, here's the attachment :-)

Marco Canini wrote:

> I attach here a modified versrion of ProviderSectionHandler that solves 
> some pbs i had while trying to use mono.data.providerfactory.
> A more detailed comment is included in the file header.
> 
> I don't send a patch because last time Miguel wasn't able to apply.
> 
> I modified ProviderSectionHandler.cs shipped with mcs 0.28
> 
> Please commit it to CVS and let Mono.Data.dll be built by default in 
> make all.
> 
> If you've questions i'm here.
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 


--------------040600060800040208080407
Content-Type: text/plain;
 name="ProviderSectionHandler.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ProviderSectionHandler.cs"

//
// Mono.Data.ProviderSectionHandler
//
// Authors:
//   Brian Ritchie (brianlritchie@hotmail.com) 
//  
//
// Copyright (C) Brian Ritchie, 2002
// 
// Modified by Marco Canini <marco.canini@fastwebnet.it> on 24 October 2003
// * Use XPath to select all provider node under providers to get sure it doesn't
//   throw exception when there're comments and whitespaces in providers node

using System;
using System.Xml;
using System.Configuration;

namespace Mono.Data
{
	public class ProviderSectionHandler : IConfigurationSectionHandler
	{
		public virtual object Create(object parent,object configContext,XmlNode section)
		{
			ProviderCollection providers = new ProviderCollection ();
			
			XmlNodeList ProviderList = section.SelectNodes ("./provider");

			foreach (XmlNode ProviderNode in ProviderList) {
				Provider provider = new Provider (
					GetStringValue (ProviderNode,"name",true),
					GetStringValue (ProviderNode,"connection",true),
					GetStringValue (ProviderNode,"adapter",true),
					GetStringValue (ProviderNode,"command",true),
					GetStringValue (ProviderNode,"assembly",true),
					GetStringValue (ProviderNode,"description",false));
				providers.Add (provider);
			}
			return providers;
		}

		private string GetStringValue(XmlNode _node, string _attribute, bool required)
		{
			XmlNode a = _node.Attributes.RemoveNamedItem (_attribute);
			if (a == null) {
				if (required)
					throw new ConfigurationException ("Attribute required: " + _attribute);
				else
					return null;
			}
			return a.Value;		
		}
	}
}

--------------040600060800040208080407--