1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.application.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.seasar.framework.util.StringUtil; |
23 | |
import org.seasar.teeda.core.JsfConstants; |
24 | |
import org.seasar.teeda.core.application.ComponentLookupStrategy; |
25 | |
import org.seasar.teeda.core.util.DIContainerUtil; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class DefaultComponentLookupStrategy implements ComponentLookupStrategy { |
31 | |
|
32 | 54 | private List namespaces = new ArrayList(); |
33 | |
|
34 | 54 | public DefaultComponentLookupStrategy() { |
35 | 54 | namespaces.add(JsfConstants.TEEDA_NAMESPACE); |
36 | 54 | } |
37 | |
|
38 | |
public Object getComponentByName(String componentName) { |
39 | 21 | if (StringUtil.isEmpty(componentName)) { |
40 | 0 | throw new IllegalArgumentException(); |
41 | |
} |
42 | 21 | Object component = DIContainerUtil |
43 | |
.getComponentNoException(componentName); |
44 | 21 | if (component != null) { |
45 | 9 | return component; |
46 | |
} |
47 | 12 | for (Iterator itr = namespaces.iterator(); itr.hasNext();) { |
48 | 12 | String namespace = (String) itr.next(); |
49 | 12 | component = getComponentByDefaultNamespace(namespace, componentName); |
50 | 12 | if (component != null) { |
51 | 0 | return component; |
52 | |
} |
53 | |
} |
54 | 12 | return null; |
55 | |
} |
56 | |
|
57 | |
public Object getComponentByClass(Class componentClazz) { |
58 | 2 | if (componentClazz == null) { |
59 | 0 | throw new IllegalArgumentException(); |
60 | |
} |
61 | 2 | return DIContainerUtil.getComponentNoException(componentClazz); |
62 | |
} |
63 | |
|
64 | |
public void addNamespace(String namespace) { |
65 | 1 | if (!StringUtil.isEmpty(namespace)) { |
66 | 1 | this.namespaces.add(namespace); |
67 | |
} |
68 | 1 | } |
69 | |
|
70 | |
private Object getComponentByDefaultNamespace(String namespace, |
71 | |
String componentName) { |
72 | 12 | final String key = new String(new StringBuffer(namespace.length() |
73 | |
+ componentName.length() + 1).append(namespace).append( |
74 | |
JsfConstants.NS_SEP).append(componentName)); |
75 | 12 | return DIContainerUtil.getComponentNoException(key); |
76 | |
} |
77 | |
} |