forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractBytecodeProvider.cs
118 lines (102 loc) · 3.22 KB
/
AbstractBytecodeProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using NHibernate.Properties;
using NHibernate.Util;
namespace NHibernate.Bytecode
{
public abstract class AbstractBytecodeProvider : IBytecodeProvider, IInjectableProxyFactoryFactory, IInjectableCollectionTypeFactoryClass
{
protected System.Type proxyFactoryFactory;
private ICollectionTypeFactory collectionTypeFactory;
private System.Type collectionTypeFactoryClass = typeof(Type.DefaultCollectionTypeFactory);
#region IBytecodeProvider Members
public virtual IProxyFactoryFactory ProxyFactoryFactory
{
get
{
if (proxyFactoryFactory != null)
{
try
{
return (IProxyFactoryFactory) Cfg.Environment.ObjectsFactory.CreateInstance(proxyFactoryFactory);
}
catch (Exception e)
{
throw new HibernateByteCodeException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e);
}
}
return StaticProxyFactoryFactory.Instance;
}
}
public abstract IReflectionOptimizer GetReflectionOptimizer(System.Type clazz, IGetter[] getters, ISetter[] setters);
// Since 5.2
[Obsolete("Please use NHibernate.Cfg.Environment.ObjectsFactory instead")]
public virtual IObjectsFactory ObjectsFactory => Cfg.Environment.ObjectsFactory;
public virtual ICollectionTypeFactory CollectionTypeFactory
{
get
{
if (collectionTypeFactory == null)
{
try
{
collectionTypeFactory =
(ICollectionTypeFactory) Cfg.Environment.ObjectsFactory.CreateInstance(collectionTypeFactoryClass);
}
catch (Exception e)
{
throw new HibernateByteCodeException("Failed to create an instance of CollectionTypeFactory!", e);
}
}
return collectionTypeFactory;
}
}
#endregion
#region IInjectableProxyFactoryFactory Members
public virtual void SetProxyFactoryFactory(string typeName)
{
System.Type pffc;
try
{
pffc = ReflectHelper.ClassForName(typeName);
}
catch (Exception he)
{
throw new UnableToLoadProxyFactoryFactoryException(typeName, he);
}
if (typeof(IProxyFactoryFactory).IsAssignableFrom(pffc) == false)
{
var he = new HibernateByteCodeException(pffc.FullName + " does not implement " + typeof(IProxyFactoryFactory).FullName);
throw he;
}
proxyFactoryFactory = pffc;
}
#endregion
#region Implementation of IInjectableCollectionTypeFactoryClass
public void SetCollectionTypeFactoryClass(string typeAssemblyQualifiedName)
{
if (string.IsNullOrEmpty(typeAssemblyQualifiedName))
{
throw new ArgumentNullException("typeAssemblyQualifiedName");
}
System.Type ctf= ReflectHelper.ClassForName(typeAssemblyQualifiedName);
SetCollectionTypeFactoryClass(ctf);
}
public void SetCollectionTypeFactoryClass(System.Type type)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (typeof(ICollectionTypeFactory).IsAssignableFrom(type) == false)
{
throw new HibernateByteCodeException(type.FullName + " does not implement " + typeof(ICollectionTypeFactory).FullName);
}
if (collectionTypeFactory != null && !collectionTypeFactoryClass.Equals(type))
{
throw new InvalidOperationException("CollectionTypeFactory in use, can't change it.");
}
collectionTypeFactoryClass = type;
}
#endregion
}
}