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.Xml;
|
22
|
|
using Seasar.Framework.Util;
|
23
|
|
using Seasar.Framework.Container.Impl;
|
24
|
|
using Seasar.Framework.Container.Util;
|
25
|
|
|
26
|
|
namespace Seasar.Framework.Container.Factory
|
27
|
|
{
|
28
|
|
|
29
|
|
|
30
|
|
|
31
|
|
public class ComponentTagHandler : TagHandler
|
32
|
|
{
|
33
|
|
|
34
|
655
|
public override void Start(TagHandlerContext context, IAttributes attributes)
|
35
|
|
{
|
36
|
655
|
IComponentDef componentDef = null;
|
37
|
655
|
string className = attributes["class"];
|
38
|
655
|
Type componentType = null;
|
39
|
655
|
IS2Container container = (IS2Container) context.Peek(0);
|
40
|
655
|
if(className != null)
|
41
|
|
{
|
42
|
601
|
Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
|
43
|
601
|
componentType = ClassUtil.ForName(className,asms);
|
44
|
601
|
if(componentType == null)
|
45
|
0
|
throw new ClassNotFoundRuntimeException(className);
|
46
|
|
}
|
47
|
655
|
string name = attributes["name"];
|
48
|
655
|
componentDef = new ComponentDefImpl(componentType,name);
|
49
|
655
|
string instanceMode = attributes["instance"];
|
50
|
655
|
if(instanceMode != null) componentDef.InstanceMode = instanceMode;
|
51
|
655
|
string autoBindingMode = attributes["autoBinding"];
|
52
|
655
|
if(autoBindingMode != null) componentDef.AutoBindingMode = autoBindingMode;
|
53
|
655
|
context.Push(componentDef);
|
54
|
|
}
|
55
|
|
|
56
|
655
|
public override void End(TagHandlerContext context, string body)
|
57
|
|
{
|
58
|
655
|
IComponentDef componentDef = (IComponentDef) context.Pop();
|
59
|
655
|
string expression = null;
|
60
|
655
|
if(body != null)
|
61
|
|
{
|
62
|
655
|
expression = body.Trim();
|
63
|
655
|
if(!StringUtil.IsEmpty(expression))
|
64
|
|
{
|
65
|
52
|
componentDef.Expression = expression;
|
66
|
|
}
|
67
|
|
else
|
68
|
|
{
|
69
|
603
|
expression = null;
|
70
|
|
}
|
71
|
|
}
|
72
|
655
|
if(componentDef.ComponentType == null
|
73
|
|
&& !InstanceModeUtil.IsOuter(componentDef.InstanceMode)
|
74
|
|
&& expression == null)
|
75
|
|
{
|
76
|
0
|
throw new TagAttributeNotDefinedRuntimeException("component","class");
|
77
|
|
}
|
78
|
655
|
if(context.Peek() is IS2Container)
|
79
|
|
{
|
80
|
453
|
IS2Container container = (IS2Container) context.Peek();
|
81
|
453
|
container.Register(componentDef);
|
82
|
|
}
|
83
|
|
else
|
84
|
|
{
|
85
|
202
|
IArgDef argDef = (IArgDef) context.Peek();
|
86
|
202
|
argDef.ChildComponentDef = componentDef;
|
87
|
|
}
|
88
|
|
}
|
89
|
|
|
90
|
|
}
|
91
|
|
}
|