1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Reflection;
|
21
|
|
using Seasar.Framework.Beans;
|
22
|
|
using Seasar.Framework.Container.Util;
|
23
|
|
using Seasar.Framework.Util;
|
24
|
|
|
25
|
|
namespace Seasar.Framework.Container.Assembler
|
26
|
|
{
|
27
|
|
|
28
|
|
|
29
|
|
|
30
|
|
public class ManualConstructorAssembler : AbstractConstructorAssembler
|
31
|
|
{
|
32
|
88
|
public ManualConstructorAssembler(IComponentDef componentDef)
|
33
|
|
: base(componentDef)
|
34
|
|
{
|
35
|
|
}
|
36
|
|
|
37
|
89
|
public override object Assemble()
|
38
|
|
{
|
39
|
89
|
object[] args = new object[this.ComponentDef.ArgDefSize];
|
40
|
|
|
41
|
186
|
for(int i = 0; i < args.Length; ++i)
|
42
|
|
{
|
43
|
98
|
try
|
44
|
|
{
|
45
|
98
|
args[i] = this.ComponentDef.GetArgDef(i).Value;
|
46
|
|
}
|
47
|
|
catch(ComponentNotFoundRuntimeException cause)
|
48
|
|
{
|
49
|
0
|
throw new IllegalConstructorRuntimeException(
|
50
|
|
this.ComponentDef.ComponentType,cause);
|
51
|
|
}
|
52
|
|
}
|
53
|
|
|
54
|
88
|
ConstructorInfo constructor =
|
55
|
|
this.ComponentDef.ComponentType.GetConstructor(
|
56
|
|
Type.GetTypeArray(args));
|
57
|
|
|
58
|
88
|
if(constructor == null)
|
59
|
0
|
throw new ConstructorNotFoundRuntimeException(
|
60
|
|
this.ComponentDef.ComponentType, args);
|
61
|
|
|
62
|
88
|
ParameterInfo[] parameters = constructor.GetParameters();
|
63
|
|
|
64
|
185
|
for (int i = 0; i < args.Length; ++i)
|
65
|
|
{
|
66
|
97
|
IArgDef argDef = this.ComponentDef.GetArgDef(i);
|
67
|
97
|
object value = this.GetComponentByReceiveType(parameters[i].ParameterType, argDef.Expression);
|
68
|
97
|
if (value != null) args[i] = value;
|
69
|
|
}
|
70
|
|
|
71
|
88
|
object obj = ConstructorUtil.NewInstance(constructor,args);
|
72
|
88
|
if(this.ComponentDef.ComponentType.IsInterface && this.ComponentDef.AspectDefSize > 0)
|
73
|
|
{
|
74
|
0
|
AopProxyUtil.WeaveAspect(ref obj,this.ComponentDef);
|
75
|
|
}
|
76
|
88
|
return obj;
|
77
|
|
}
|
78
|
|
|
79
|
|
}
|
80
|
|
}
|
81
|
|
|