Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28688
Modified Files:
Configuration.cs
Log Message:
Added more ways to Configure NH-127
Index: Configuration.cs
===================================================================
RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Configuration.cs,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** Configuration.cs 9 Aug 2004 03:14:08 -0000 1.20
--- Configuration.cs 28 Sep 2004 01:08:40 -0000 1.21
***************
*** 679,684 ****
public Configuration Configure()
{
! Configure("hibernate.cfg.xml");
! return this;
}
--- 679,683 ----
public Configuration Configure()
{
! return Configure("hibernate.cfg.xml");
}
***************
*** 693,704 ****
public Configuration Configure(string resource)
{
XmlDocument doc = new XmlDocument();
XmlValidatingReader validatingReader = null;
! XmlTextReader reader = null;
!
try
{
- reader = new XmlTextReader(resource);
validatingReader = new XmlValidatingReader( reader );
validatingReader.ValidationType = ValidationType.Schema;
--- 692,746 ----
public Configuration Configure(string resource)
{
+ XmlTextReader reader = new XmlTextReader( resource );
+ return Configure( reader );
+ }
+
+ /// <summary>
+ /// Configure NHibernate using a resource contained in an Assembly.
+ /// </summary>
+ /// <param name="assembly">The <see cref="Assembly"/> that contains the resource.</param>
+ /// <param name="resourceName">The name of the manifest resource being requested.</param>
+ /// <returns>A Configuration object initialized from the manifest resource.</returns>
+ /// <remarks>
+ /// Calling Configure(Assembly, string) will overwrite the values set in app.config or web.config
+ /// </remarks>
+ public Configuration Configure(Assembly assembly, string resourceName)
+ {
+ if( assembly==null || resourceName==null )
+ {
+ throw new HibernateException( "Could not configure NHibernate.", new ArgumentException( "A null value was passed in.", "assembly or resourceName" ) );
+ }
+
+ Stream stream = assembly.GetManifestResourceStream( resourceName );
+ if (stream==null)
+ {
+ // resource does not exist - throw appropriate exception
+ throw new HibernateException( "A ManifestResourceStream could not be created for the resource " + resourceName + " in Assembly " + assembly.FullName );
+ }
+
+ return Configure( new XmlTextReader( stream ) );
+ }
+
+ /// <summary>
+ /// Configure NHibernate using the specified XmlTextReader.
+ /// </summary>
+ /// <param name="reader">The <see cref="XmlTextReader"/> that contains the Xml to configure NHibernate.</param>
+ /// <returns>A Configuration object initialized with the file.</returns>
+ /// <remarks>
+ /// Calling Configure(XmlTextReader) will overwrite the values set in app.config or web.config
+ /// </remarks>
+ public Configuration Configure(XmlTextReader reader)
+ {
+ if( reader==null )
+ {
+ throw new HibernateException( "Could not configure NHibernate.", new ArgumentException( "A null value was passed in.", "reader" ) );
+ }
+
XmlDocument doc = new XmlDocument();
XmlValidatingReader validatingReader = null;
!
try
{
validatingReader = new XmlValidatingReader( reader );
validatingReader.ValidationType = ValidationType.Schema;
***************
*** 715,720 ****
catch (Exception e)
{
! log.Error("Problem parsing configuraiton " + resource, e);
! throw new HibernateException("problem parsing configuration " + resource + ": " + e);
}
--- 757,762 ----
catch (Exception e)
{
! log.Error("Problem parsing configuration", e);
! throw new HibernateException("problem parsing configuration : " + e);
}
***************
*** 726,730 ****
foreach(XmlNode mapElement in sfNode.ChildNodes)
{
- //string elemname = mapElement.Name;
string elemname = mapElement.LocalName;
if ( "mapping".Equals(elemname) )
--- 768,771 ----
|