From: Michael D. <mik...@us...> - 2004-07-12 02:26:37
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14968/NHibernate/Cfg Modified Files: Configuration.cs Log Message: hibernate.cfg.xml now requires a reference to the configuration schema. Index: Configuration.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Configuration.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Configuration.cs 12 Jul 2004 01:28:50 -0000 1.16 --- Configuration.cs 12 Jul 2004 02:26:28 -0000 1.17 *************** *** 15,19 **** using NHibernate.Engine; ! namespace NHibernate.Cfg { /// <summary> /// An instance of <c>Configuration</c> allows the application to specify properties --- 15,20 ---- using NHibernate.Engine; ! namespace NHibernate.Cfg ! { /// <summary> /// An instance of <c>Configuration</c> allows the application to specify properties *************** *** 42,50 **** private XmlSchema mappingSchema; public readonly static string MappingSchemaXMLNS = "urn:nhibernate-mapping-2.0"; private readonly static string MappingSchemaResource = "NHibernate.nhibernate-mapping-2.0.xsd"; ! protected void Reset() { classes = new Hashtable(); collections = new Hashtable(); --- 43,59 ---- private XmlSchema mappingSchema; + private XmlSchema cfgSchema; public readonly static string MappingSchemaXMLNS = "urn:nhibernate-mapping-2.0"; private readonly static string MappingSchemaResource = "NHibernate.nhibernate-mapping-2.0.xsd"; ! public readonly static string CfgSchemaXMLNS = "urn:nhibernate-configuration-2.0"; ! private readonly static string CfgSchemaResource = "NHibernate.nhibernate-configuration-2.0.xsd"; ! private readonly static string CfgNamespacePrefix = "cfg"; ! private static XmlNamespaceManager CfgNamespaceMgr; ! ! ! protected void Reset() ! { classes = new Hashtable(); collections = new Hashtable(); *************** *** 56,62 **** } ! public Configuration() { Reset(); mappingSchema = XmlSchema.Read(Assembly.GetExecutingAssembly().GetManifestResourceStream(MappingSchemaResource), null); } --- 65,76 ---- } ! /// <summary> ! /// Create a new Configuration object. ! /// </summary> ! public Configuration() ! { Reset(); mappingSchema = XmlSchema.Read(Assembly.GetExecutingAssembly().GetManifestResourceStream(MappingSchemaResource), null); + cfgSchema = XmlSchema.Read(Assembly.GetExecutingAssembly().GetManifestResourceStream(CfgSchemaResource), null); } *************** *** 640,644 **** private void AddProperties(XmlNode parent) { ! foreach(XmlNode node in parent.SelectNodes("property")) { string name = node.Attributes["name"].Value; --- 654,658 ---- private void AddProperties(XmlNode parent) { ! foreach(XmlNode node in parent.SelectNodes(CfgNamespacePrefix + ":property", CfgNamespaceMgr)) { string name = node.Attributes["name"].Value; *************** *** 678,684 **** XmlDocument doc = new XmlDocument(); try { ! doc.Load(resource); } catch (Exception e) --- 692,712 ---- XmlDocument doc = new XmlDocument(); + XmlValidatingReader validatingReader = null; + XmlTextReader reader = null; + try { ! reader = new XmlTextReader(resource); ! validatingReader = new XmlValidatingReader( reader ); ! validatingReader.ValidationType = ValidationType.Schema; ! validatingReader.Schemas.Add(cfgSchema); ! ! doc.Load(validatingReader); ! CfgNamespaceMgr = new XmlNamespaceManager(doc.NameTable); ! // note that the prefix has absolutely nothing to do with what the user ! // selects as their prefix in the document. It is the prefix we use to ! // build the XPath and the nsmgr takes care of translating our prefix into ! // the user defined prefix... ! CfgNamespaceMgr.AddNamespace(CfgNamespacePrefix, Configuration.CfgSchemaXMLNS); } catch (Exception e) *************** *** 688,699 **** } ! XmlNode sfNode = doc.DocumentElement.SelectSingleNode("session-factory"); XmlAttribute name = sfNode.Attributes["name"]; ! if (name!=null) properties.Add(Environment.SessionFactoryName, name.Value); AddProperties(sfNode); foreach(XmlNode mapElement in sfNode.ChildNodes) { ! string elemname = mapElement.Name; if ( "mapping".Equals(elemname) ) { --- 716,728 ---- } ! XmlNode sfNode = doc.DocumentElement.SelectSingleNode(CfgNamespacePrefix + ":session-factory", CfgNamespaceMgr); XmlAttribute name = sfNode.Attributes["name"]; ! if (name!=null) properties[Environment.SessionFactoryName] = name.Value; AddProperties(sfNode); foreach(XmlNode mapElement in sfNode.ChildNodes) { ! //string elemname = mapElement.Name; ! string elemname = mapElement.LocalName; if ( "mapping".Equals(elemname) ) { *************** *** 723,726 **** --- 752,756 ---- log.Debug("properties: " + properties); + validatingReader.Close(); return this; } |