1 | |
package org.seasar.uruma.container.warmdeploy; |
2 | |
|
3 | |
import org.seasar.framework.container.ComponentCreator; |
4 | |
import org.seasar.framework.container.ComponentDef; |
5 | |
import org.seasar.framework.container.S2Container; |
6 | |
import org.seasar.framework.container.factory.SingletonS2ContainerFactory; |
7 | |
import org.seasar.framework.container.impl.S2ContainerBehavior.DefaultProvider; |
8 | |
import org.seasar.framework.container.util.S2ContainerUtil; |
9 | |
import org.seasar.framework.convention.NamingConvention; |
10 | |
import org.seasar.framework.log.Logger; |
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | 0 | public class UrumaWarmdeployBehavior extends DefaultProvider { |
20 | |
|
21 | 0 | private static final Logger logger = Logger |
22 | |
.getLogger(UrumaWarmdeployBehavior.class); |
23 | |
|
24 | |
private NamingConvention namingConvention; |
25 | |
|
26 | 0 | private ComponentCreator[] creators = new ComponentCreator[0]; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public NamingConvention getNamingConvention() { |
34 | 0 | return namingConvention; |
35 | |
} |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public void setNamingConvention(final NamingConvention namingConvention) { |
44 | 0 | this.namingConvention = namingConvention; |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public ComponentCreator[] getCreators() { |
53 | 0 | return creators; |
54 | |
} |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public void setCreators(final ComponentCreator[] creators) { |
63 | 0 | this.creators = creators; |
64 | 0 | } |
65 | |
|
66 | |
@Override |
67 | |
protected ComponentDef getComponentDef(final S2Container container, |
68 | |
final Object key) { |
69 | 0 | synchronized (container.getRoot()) { |
70 | 0 | ComponentDef cd = super.getComponentDef(container, key); |
71 | 0 | if (cd != null) { |
72 | 0 | return cd; |
73 | |
} |
74 | 0 | if (container != container.getRoot()) { |
75 | 0 | return null; |
76 | |
} |
77 | |
|
78 | 0 | if (key instanceof Class) { |
79 | 0 | cd = createComponentDef((Class) key); |
80 | 0 | } else if (key instanceof String) { |
81 | 0 | cd = createComponentDef((String) key); |
82 | 0 | if (cd != null && !key.equals(cd.getComponentName())) { |
83 | 0 | logger.log("WSSR0011", new Object[] { key, |
84 | |
cd.getComponentClass().getName(), |
85 | |
cd.getComponentName() }); |
86 | 0 | cd = null; |
87 | |
} |
88 | |
} else { |
89 | 0 | throw new IllegalArgumentException("key"); |
90 | |
} |
91 | 0 | if (cd != null) { |
92 | 0 | SingletonS2ContainerFactory.getContainer().register(cd); |
93 | 0 | S2ContainerUtil.putRegisterLog(cd); |
94 | 0 | cd.init(); |
95 | |
} |
96 | 0 | return cd; |
97 | 0 | } |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
protected ComponentDef createComponentDef(final Class componentClass) { |
112 | 0 | for (int i = 0; i < creators.length; ++i) { |
113 | 0 | ComponentCreator creator = creators[i]; |
114 | 0 | ComponentDef cd = creator.createComponentDef(componentClass); |
115 | 0 | if (cd != null) { |
116 | 0 | return cd; |
117 | |
} |
118 | |
} |
119 | 0 | return null; |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
protected ComponentDef createComponentDef(final String componentName) { |
134 | 0 | for (int i = 0; i < creators.length; ++i) { |
135 | 0 | ComponentCreator creator = creators[i]; |
136 | 0 | ComponentDef cd = creator.createComponentDef(componentName); |
137 | 0 | if (cd != null) { |
138 | 0 | return cd; |
139 | |
} |
140 | |
} |
141 | 0 | return null; |
142 | |
} |
143 | |
|
144 | |
} |