From: <fab...@us...> - 2008-11-08 15:15:00
|
Revision: 3896 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3896&view=rev Author: fabiomaulo Date: 2008-11-08 15:14:52 +0000 (Sat, 08 Nov 2008) Log Message: ----------- - Removed default ProxyFactoryFactory. - Improv Exceptions related with ProxyFactoryFactory Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Bytecode/CodeDom/BytecodeProviderImpl.cs trunk/nhibernate/src/NHibernate/Bytecode/Lightweight/BytecodeProviderImpl.cs trunk/nhibernate/src/NHibernate/Bytecode/NullBytecodeProvider.cs trunk/nhibernate/src/NHibernate/Cfg/Environment.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Bytecode/HibernateByteCodeException.cs trunk/nhibernate/src/NHibernate/Bytecode/ProxyFactoryFactoryNotConfiguredException.cs trunk/nhibernate/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs trunk/nhibernate/src/NHibernate.Test/Bytecode/ trunk/nhibernate/src/NHibernate.Test/Bytecode/Lightweight/ trunk/nhibernate/src/NHibernate.Test/Bytecode/Lightweight/BytecodeProviderFixture.cs trunk/nhibernate/src/NHibernate.Test/Bytecode/WrongProxyFactoryFactory.cs Modified: trunk/nhibernate/src/NHibernate/Bytecode/CodeDom/BytecodeProviderImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Bytecode/CodeDom/BytecodeProviderImpl.cs 2008-11-07 22:40:43 UTC (rev 3895) +++ trunk/nhibernate/src/NHibernate/Bytecode/CodeDom/BytecodeProviderImpl.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -31,11 +31,11 @@ } catch (Exception e) { - throw new HibernateException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e); + throw new HibernateByteCodeException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e); } } - throw new HibernateException("The ProxyFactoryFactory was not configured. Initialize the 'proxyfactory.factory_class' property of the session-factory section."); + throw new ProxyFactoryFactoryNotConfiguredException(); } } @@ -61,15 +61,14 @@ { pffc = ReflectHelper.ClassForName(typeName); } - catch (HibernateException he) + catch (Exception he) { - throw new HibernateException("Unable to load type '" + typeName + "' during configuration of proxy factory class.", - he); + throw new UnableToLoadProxyFactoryFactoryException(typeName, he); } if (typeof (IProxyFactoryFactory).IsAssignableFrom(pffc) == false) { - var he = new HibernateException(pffc.FullName + " does not implement " + typeof (IProxyFactoryFactory).FullName); + var he = new HibernateByteCodeException(pffc.FullName + " does not implement " + typeof(IProxyFactoryFactory).FullName); throw he; } proxyFactoryFactory = pffc; Added: trunk/nhibernate/src/NHibernate/Bytecode/HibernateByteCodeException.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Bytecode/HibernateByteCodeException.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Bytecode/HibernateByteCodeException.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -0,0 +1,15 @@ +using System; +using System.Runtime.Serialization; + +namespace NHibernate.Bytecode +{ + [Serializable] + public class HibernateByteCodeException : HibernateException + { + public HibernateByteCodeException() {} + public HibernateByteCodeException(string message) : base(message) {} + public HibernateByteCodeException(string message, Exception inner) : base(message, inner) {} + + protected HibernateByteCodeException(SerializationInfo info, StreamingContext context) : base(info, context) {} + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Bytecode/Lightweight/BytecodeProviderImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Bytecode/Lightweight/BytecodeProviderImpl.cs 2008-11-07 22:40:43 UTC (rev 3895) +++ trunk/nhibernate/src/NHibernate/Bytecode/Lightweight/BytecodeProviderImpl.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -30,10 +30,10 @@ } catch (Exception e) { - throw new HibernateException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e); + throw new HibernateByteCodeException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e); } } - throw new HibernateException("The ProxyFactoryFactory was not configured. Initialize the 'proxyfactory.factory_class' property of the session-factory section."); + throw new ProxyFactoryFactoryNotConfiguredException(); } } @@ -60,15 +60,14 @@ { pffc = ReflectHelper.ClassForName(typeName); } - catch (HibernateException he) + catch (Exception he) { - throw new HibernateException("Unable to load type '" + typeName + "' during configuration of proxy factory class.", - he); + throw new UnableToLoadProxyFactoryFactoryException(typeName, he); } if (typeof (IProxyFactoryFactory).IsAssignableFrom(pffc) == false) { - var he = new HibernateException(pffc.FullName + " does not implement " + typeof (IProxyFactoryFactory).FullName); + var he = new HibernateByteCodeException(pffc.FullName + " does not implement " + typeof(IProxyFactoryFactory).FullName); throw he; } proxyFactoryFactory = pffc; Modified: trunk/nhibernate/src/NHibernate/Bytecode/NullBytecodeProvider.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Bytecode/NullBytecodeProvider.cs 2008-11-07 22:40:43 UTC (rev 3895) +++ trunk/nhibernate/src/NHibernate/Bytecode/NullBytecodeProvider.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -26,10 +26,10 @@ } catch (Exception e) { - throw new HibernateException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e); + throw new HibernateByteCodeException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e); } } - throw new HibernateException("The ProxyFactoryFactory was not configured. Initialize the 'proxyfactory.factory_class' property of the session-factory section."); + throw new ProxyFactoryFactoryNotConfiguredException(); } } @@ -49,15 +49,14 @@ { pffc = ReflectHelper.ClassForName(typeName); } - catch (HibernateException he) + catch (Exception he) { - throw new HibernateException("Unable to load type '" + typeName + "' during configuration of proxy factory class.", - he); + throw new UnableToLoadProxyFactoryFactoryException(typeName, he); } if (typeof (IProxyFactoryFactory).IsAssignableFrom(pffc) == false) { - var he = new HibernateException(pffc.FullName + " does not implement " + typeof (IProxyFactoryFactory).FullName); + var he = new HibernateByteCodeException(pffc.FullName + " does not implement " + typeof(IProxyFactoryFactory).FullName); throw he; } proxyFactoryFactory = pffc; Added: trunk/nhibernate/src/NHibernate/Bytecode/ProxyFactoryFactoryNotConfiguredException.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Bytecode/ProxyFactoryFactoryNotConfiguredException.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Bytecode/ProxyFactoryFactoryNotConfiguredException.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -0,0 +1,29 @@ +using System; +using System.Runtime.Serialization; + +namespace NHibernate.Bytecode +{ + + [Serializable] + public class ProxyFactoryFactoryNotConfiguredException : HibernateByteCodeException + { + public ProxyFactoryFactoryNotConfiguredException() {} + + protected ProxyFactoryFactoryNotConfiguredException(SerializationInfo info, + StreamingContext context) : base(info, context) {} + + public override string Message + { + get + { + const string msg = @"The ProxyFactoryFactory was not configured. +Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. +Example: +<property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> +Example: +<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>"; + return msg; + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -0,0 +1,37 @@ +using System; +using System.Runtime.Serialization; + +namespace NHibernate.Bytecode +{ + [Serializable] + public class UnableToLoadProxyFactoryFactoryException : HibernateByteCodeException + { + private readonly string typeName; + public UnableToLoadProxyFactoryFactoryException(string typeName, Exception inner) + : base("", inner) + { + this.typeName = typeName; + } + + protected UnableToLoadProxyFactoryFactoryException(SerializationInfo info, + StreamingContext context) : base(info, context) {} + public override string Message + { + get + { + const string causes = @" +Possible causes are: +- The NHibernate.Bytecode provider assembly was not deployed. +- The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed. + +Solution: +Confirm that your deployment folder contains one of the following assemblies: +NHibernate.ByteCode.LinFu.dll +NHibernate.ByteCode.Castle.dll"; + string msg = "Unable to load type '" + typeName + "' during configuration of proxy factory class." + causes; + + return msg; + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/Environment.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Environment.cs 2008-11-07 22:40:43 UTC (rev 3895) +++ trunk/nhibernate/src/NHibernate/Cfg/Environment.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -178,7 +178,6 @@ GlobalProperties = new Dictionary<string, string>(); GlobalProperties[PropertyUseReflectionOptimizer] = bool.TrueString; - SetDefaultProxyFactoryFactory(); LoadGlobalPropertiesFromAppConfig(); VerifyProperties(GlobalProperties); @@ -191,12 +190,6 @@ } } - private static void SetDefaultProxyFactoryFactory() - { - // maitaining the optionality of set the proxyfactory.factory_class property - GlobalProperties[ProxyFactoryFactoryClass] = "NHibernate.ProxyGenerators.CastleDynamicProxy.ProxyFactoryFactory, NHibernate.ProxyGenerators.CastleDynamicProxy"; - } - private static void LoadGlobalPropertiesFromAppConfig() { object config = ConfigurationManager.GetSection(CfgXmlHelper.CfgSectionName); @@ -252,8 +245,6 @@ { GlobalProperties[PropertyUseReflectionOptimizer] = savedUseReflectionOptimizer; } - - SetDefaultProxyFactoryFactory(); } /// <summary> Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2008-11-07 22:40:43 UTC (rev 3895) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2008-11-08 15:14:52 UTC (rev 3896) @@ -440,6 +440,9 @@ <Compile Include="AdoNet\ResultSetWrapper.cs" /> <Compile Include="AdoNet\SqlClientBatchingBatcherFactory.cs" /> <Compile Include="AdoNet\TooManyRowsAffectedException.cs" /> + <Compile Include="Bytecode\HibernateByteCodeException.cs" /> + <Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" /> + <Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" /> <Compile Include="Id\SelectGenerator.cs" /> <Compile Include="Properties\BackFieldStrategy.cs" /> <Compile Include="Bytecode\CodeDom\BytecodeProviderImpl.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/Bytecode/Lightweight/BytecodeProviderFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Bytecode/Lightweight/BytecodeProviderFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Bytecode/Lightweight/BytecodeProviderFixture.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -0,0 +1,76 @@ +using NHibernate.Bytecode; +using NHibernate.Bytecode.Lightweight; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.Bytecode.Lightweight +{ + [TestFixture] + public class BytecodeProviderFixture + { + [Test] + public void NotConfiguredProxyFactoryFactory() + { + try + { + var bcp = new BytecodeProviderImpl(); + IProxyFactoryFactory p = bcp.ProxyFactoryFactory; + Assert.Fail(); + } + catch (HibernateByteCodeException e) + { + Assert.That(e.Message, Text.StartsWith("The ProxyFactoryFactory was not configured")); + Assert.That(e.Message, Text.Contains("Example")); + } + } + + [Test] + public void UnableToLoadProxyFactoryFactory() + { + try + { + var bcp = new BytecodeProviderImpl(); + bcp.SetProxyFactoryFactory("whatever"); + Assert.Fail(); + } + catch (HibernateByteCodeException e) + { + Assert.That(e.Message, Text.StartsWith("Unable to load type")); + Assert.That(e.Message, Text.Contains("Possible causes")); + Assert.That(e.Message, Text.Contains("Confirm that your deployment folder contains")); + } + } + + [Test] + public void DoesNotImplementProxyFactoryFactory() + { + try + { + var bcp = new BytecodeProviderImpl(); + bcp.SetProxyFactoryFactory(GetType().AssemblyQualifiedName); + Assert.Fail(); + } + catch (HibernateByteCodeException e) + { + Assert.That(e.Message, + Is.EqualTo(GetType().FullName + " does not implement " + typeof(IProxyFactoryFactory).FullName)); + } + } + + [Test] + public void CantCreateProxyFactoryFactory() + { + try + { + var bcp = new BytecodeProviderImpl(); + bcp.SetProxyFactoryFactory(typeof(WrongProxyFactoryFactory).AssemblyQualifiedName); + IProxyFactoryFactory p = bcp.ProxyFactoryFactory; + Assert.Fail(); + } + catch (HibernateByteCodeException e) + { + Assert.That(e.Message,Text.StartsWith("Failed to create an instance of")); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Bytecode/WrongProxyFactoryFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Bytecode/WrongProxyFactoryFactory.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Bytecode/WrongProxyFactoryFactory.cs 2008-11-08 15:14:52 UTC (rev 3896) @@ -0,0 +1,27 @@ +using NHibernate.Bytecode; +using NHibernate.Proxy; + +namespace NHibernate.Test.Bytecode +{ + public class WrongProxyFactoryFactory : IProxyFactoryFactory + { + public WrongProxyFactoryFactory() + { + throw new System.Exception(); + } + + #region Implementation of IProxyFactoryFactory + + public IProxyFactory BuildProxyFactory() + { + throw new System.NotImplementedException(); + } + + public IProxyValidator ProxyValidator + { + get { throw new System.NotImplementedException(); } + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2008-11-07 22:40:43 UTC (rev 3895) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2008-11-08 15:14:52 UTC (rev 3896) @@ -77,6 +77,8 @@ <Compile Include="AssemblyInfo.cs" /> <Compile Include="Assertions\InheritedAreMarkedSerializable.cs" /> <Compile Include="Assertions\IsSerializable.cs" /> + <Compile Include="Bytecode\Lightweight\BytecodeProviderFixture.cs" /> + <Compile Include="Bytecode\WrongProxyFactoryFactory.cs" /> <Compile Include="CacheTest\CacheFixture.cs" /> <Compile Include="CacheTest\QueryCacheFixture.cs" /> <Compile Include="CacheTest\TimestamperFixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |