www.pudn.com > Websharp2005.rar > AspectConfigHandler.cs
using System;
using System.Xml;
using System.Data;
using System.Resources;
using System.Reflection;
using System.Collections;
using System.Configuration;
namespace Websharp.Aspect
{
///
/// 读取Aspect配置文件的类
/// Class to get the configuration of Aspects.
///
public class AspectConfigHandler : IConfigurationSectionHandler
{
///
/// 由所有配置节处理程序实现,以分析配置节的 XML
///
/// 对应父配置节中的配置设置
/// 在从 ASP.NET 配置系统中调用 Create 时为 HttpConfigurationContext。否则,该参数是保留参数,并且为空引用。
/// 一个 XmlNode,它包含配置文件中的配置信息。提供对配置节 XML 内容的直接访问。
/// 配置对象
object IConfigurationSectionHandler.Create ( object parent, object context, XmlNode section )
{
AspectInfoCollection aspects=AspectsManager.Aspects;
if( Object.Equals(section, null))
{
throw(new ArgumentNullException());
}
XmlNodeList storageInfo = section.SelectNodes("Aspect"); //读取Aspect节点
if(!object.Equals(storageInfo,null)) //当配置节点不为空的时候,循环读出每个Aspect的信息
{
foreach(XmlNode node in storageInfo)
{
string[] typeName=node.Attributes["type"].Value.Split(',');
string deploymodel=node.Attributes["deploy-model"].Value;
string pointcut=node.Attributes["pointcut-type"].Value;
string actionposition=node.Attributes["action-position"].Value;
string[] match=node.Attributes["match"].Value.Split(',');
if(match[0].StartsWith("*"))
{
aspects.Add(new AspectInfo(typeName[1],typeName[0],deploymodel,pointcut,actionposition,
match[0],match[1],match[0].Substring(1,match[0].Length-1)+"--"+match[1]));
}
else
{
aspects.Add(new AspectInfo(typeName[1],typeName[0],deploymodel,pointcut,actionposition,
match[0],match[1],match[0]+"--"+match[1]));
}
}
}
return aspects;
}
}
}