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 System.Runtime.Remoting;
|
22
|
|
using Seasar.Framework.Aop.Proxy;
|
23
|
|
using Seasar.Framework.Log;
|
24
|
|
using Seasar.Framework.Container.Util;
|
25
|
|
|
26
|
|
namespace Seasar.Framework.Container.Assembler
|
27
|
|
{
|
28
|
|
|
29
|
|
|
30
|
|
|
31
|
|
public class AutoPropertyAssembler : AbstractPropertyAssembler
|
32
|
|
{
|
33
|
|
private static Logger logger_ = Logger.GetLogger(typeof(AutoPropertyAssembler));
|
34
|
|
|
35
|
466
|
public AutoPropertyAssembler(IComponentDef componentDef)
|
36
|
|
: base(componentDef)
|
37
|
|
{
|
38
|
|
}
|
39
|
|
|
40
|
468
|
public override void Assemble(object component)
|
41
|
|
{
|
42
|
468
|
Type type = component.GetType();
|
43
|
468
|
if ( RemotingServices.IsTransparentProxy(component) )
|
44
|
|
{
|
45
|
10
|
AopProxy aopProxy = RemotingServices.GetRealProxy(component) as AopProxy;
|
46
|
10
|
if (aopProxy != null)
|
47
|
|
{
|
48
|
2
|
type = aopProxy.TargetType;
|
49
|
|
}
|
50
|
|
}
|
51
|
|
|
52
|
468
|
IS2Container container = this.ComponentDef.Container;
|
53
|
468
|
foreach(PropertyInfo property in type.GetProperties())
|
54
|
|
{
|
55
|
1179
|
object value = null;
|
56
|
1179
|
string propName = property.Name;
|
57
|
1179
|
if(this.ComponentDef.HasPropertyDef(propName))
|
58
|
|
{
|
59
|
281
|
IPropertyDef propDef = this.ComponentDef.GetPropertyDef(propName);
|
60
|
|
|
61
|
281
|
value = this.GetComponentByReceiveType(property.PropertyType, propDef.Expression);
|
62
|
|
|
63
|
281
|
if(value == null) value = this.GetValue(propDef,component);
|
64
|
|
|
65
|
281
|
this.SetValue(property,component,value);
|
66
|
|
}
|
67
|
898
|
else if(property.CanWrite
|
68
|
|
&& AutoBindingUtil.IsSuitable(property.PropertyType))
|
69
|
|
{
|
70
|
314
|
try
|
71
|
|
{
|
72
|
314
|
value = container.GetComponent(property.PropertyType);
|
73
|
|
}
|
74
|
|
catch(ComponentNotFoundRuntimeException cause)
|
75
|
|
{
|
76
|
2
|
if(property.CanRead
|
77
|
|
&& property.GetValue(component,null) != null)
|
78
|
|
{
|
79
|
1
|
continue;
|
80
|
|
}
|
81
|
1
|
logger_.Log("WSSR0008",
|
82
|
|
new object[] {this.GetComponentType(
|
83
|
|
component).FullName, propName},cause);
|
84
|
1
|
continue;
|
85
|
|
}
|
86
|
312
|
this.SetValue(property,component,value);
|
87
|
|
}
|
88
|
|
|
89
|
|
}
|
90
|
|
}
|
91
|
|
|
92
|
|
}
|
93
|
|
}
|
94
|
|
|