1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
package org.apache.tapestry.services.impl;
|
16
|
|
|
17
|
|
import java.util.ArrayList;
|
18
|
|
import java.util.HashMap;
|
19
|
|
import java.util.List;
|
20
|
|
import java.util.Locale;
|
21
|
|
import java.util.Map;
|
22
|
|
|
23
|
|
import org.apache.hivemind.Resource;
|
24
|
|
import org.apache.hivemind.lib.chain.ChainBuilder;
|
25
|
|
import org.apache.tapestry.IComponent;
|
26
|
|
import org.apache.tapestry.INamespace;
|
27
|
|
import org.apache.tapestry.engine.IPropertySource;
|
28
|
|
import org.apache.tapestry.event.ResetEventListener;
|
29
|
|
import org.apache.tapestry.services.ComponentPropertySource;
|
30
|
|
import org.apache.tapestry.spec.IComponentSpecification;
|
31
|
|
import org.apache.tapestry.util.PropertyHolderPropertySource;
|
32
|
|
|
33
|
|
|
34
|
|
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
public class ComponentPropertySourceImpl implements ComponentPropertySource, ResetEventListener
|
40
|
|
{
|
41
|
|
private IPropertySource _globalProperties;
|
42
|
|
|
43
|
|
private ChainBuilder _chainBuilder;
|
44
|
|
|
45
|
|
private Map _componentSources = new HashMap();
|
46
|
|
|
47
|
|
private Map _localizedComponentSources = new HashMap();
|
48
|
|
|
49
|
|
private Map _namespaceSources = new HashMap();
|
50
|
|
|
51
|
|
private Map _localizedNamespaceSources = new HashMap();
|
52
|
|
|
53
|
0
|
public synchronized void resetEventDidOccur()
|
54
|
|
{
|
55
|
0
|
_componentSources.clear();
|
56
|
0
|
_localizedComponentSources.clear();
|
57
|
0
|
_namespaceSources.clear();
|
58
|
0
|
_localizedNamespaceSources.clear();
|
59
|
|
}
|
60
|
|
|
61
|
221
|
private synchronized IPropertySource getSourceForNamespace(INamespace namespace)
|
62
|
|
{
|
63
|
221
|
Resource key = namespace.getSpecificationLocation();
|
64
|
|
|
65
|
221
|
IPropertySource result = (IPropertySource) _namespaceSources.get(key);
|
66
|
|
|
67
|
221
|
if (result == null)
|
68
|
|
{
|
69
|
76
|
result = createSourceForNamespace(namespace);
|
70
|
76
|
_namespaceSources.put(key, result);
|
71
|
|
}
|
72
|
|
|
73
|
221
|
return result;
|
74
|
|
}
|
75
|
|
|
76
|
522
|
private synchronized IPropertySource getSourceForComponent(IComponent component)
|
77
|
|
{
|
78
|
522
|
Resource key = component.getSpecification().getSpecificationLocation();
|
79
|
|
|
80
|
522
|
IPropertySource result = (IPropertySource) _componentSources.get(key);
|
81
|
|
|
82
|
522
|
if (result == null)
|
83
|
|
{
|
84
|
165
|
result = createSourceForComponent(component);
|
85
|
165
|
_componentSources.put(key, result);
|
86
|
|
}
|
87
|
|
|
88
|
522
|
return result;
|
89
|
|
}
|
90
|
|
|
91
|
209
|
private synchronized LocalizedPropertySource getLocalizedSourceForComponent(IComponent component)
|
92
|
|
{
|
93
|
209
|
Resource key = component.getSpecification().getSpecificationLocation();
|
94
|
|
|
95
|
209
|
LocalizedPropertySource result = (LocalizedPropertySource) _localizedComponentSources
|
96
|
|
.get(key);
|
97
|
|
|
98
|
209
|
if (result == null)
|
99
|
|
{
|
100
|
165
|
result = new LocalizedPropertySource(getSourceForComponent(component));
|
101
|
|
|
102
|
165
|
_localizedComponentSources.put(key, result);
|
103
|
|
}
|
104
|
|
|
105
|
209
|
return result;
|
106
|
|
}
|
107
|
|
|
108
|
20
|
private synchronized LocalizedPropertySource getLocalizedSourceForNamespace(INamespace namespace)
|
109
|
|
{
|
110
|
20
|
Resource key = namespace.getSpecificationLocation();
|
111
|
|
|
112
|
20
|
LocalizedPropertySource result = (LocalizedPropertySource) _localizedNamespaceSources
|
113
|
|
.get(key);
|
114
|
|
|
115
|
20
|
if (result == null)
|
116
|
|
{
|
117
|
7
|
result = new LocalizedPropertySource(getSourceForNamespace(namespace));
|
118
|
|
|
119
|
7
|
_localizedNamespaceSources.put(key, result);
|
120
|
|
}
|
121
|
|
|
122
|
20
|
return result;
|
123
|
|
}
|
124
|
|
|
125
|
165
|
private IPropertySource createSourceForComponent(IComponent component)
|
126
|
|
{
|
127
|
165
|
IComponentSpecification specification = component.getSpecification();
|
128
|
|
|
129
|
165
|
List sources = new ArrayList();
|
130
|
|
|
131
|
165
|
sources.add(new PropertyHolderPropertySource(specification));
|
132
|
165
|
sources.add(getSourceForNamespace(component.getNamespace()));
|
133
|
|
|
134
|
165
|
return (IPropertySource) _chainBuilder.buildImplementation(
|
135
|
|
IPropertySource.class,
|
136
|
|
sources,
|
137
|
|
ImplMessages.componentPropertySourceDescription(specification));
|
138
|
|
}
|
139
|
|
|
140
|
76
|
private IPropertySource createSourceForNamespace(INamespace namespace)
|
141
|
|
{
|
142
|
76
|
List sources = new ArrayList();
|
143
|
|
|
144
|
76
|
sources.add(new PropertyHolderPropertySource(namespace.getSpecification()));
|
145
|
76
|
sources.add(_globalProperties);
|
146
|
|
|
147
|
76
|
return (IPropertySource) _chainBuilder.buildImplementation(
|
148
|
|
IPropertySource.class,
|
149
|
|
sources,
|
150
|
|
ImplMessages.namespacePropertySourceDescription(namespace));
|
151
|
|
}
|
152
|
|
|
153
|
357
|
public String getComponentProperty(IComponent component, String propertyName)
|
154
|
|
{
|
155
|
357
|
return getSourceForComponent(component).getPropertyValue(propertyName);
|
156
|
|
}
|
157
|
|
|
158
|
209
|
public String getLocalizedComponentProperty(IComponent component, Locale locale,
|
159
|
|
String propertyName)
|
160
|
|
{
|
161
|
209
|
return getLocalizedSourceForComponent(component).getPropertyValue(propertyName, locale);
|
162
|
|
}
|
163
|
|
|
164
|
49
|
public String getNamespaceProperty(INamespace namespace, String propertyName)
|
165
|
|
{
|
166
|
49
|
return getSourceForNamespace(namespace).getPropertyValue(propertyName);
|
167
|
|
}
|
168
|
|
|
169
|
20
|
public String getLocalizedNamespaceProperty(INamespace namespace, Locale locale,
|
170
|
|
String propertyName)
|
171
|
|
{
|
172
|
20
|
return getLocalizedSourceForNamespace(namespace).getPropertyValue(propertyName, locale);
|
173
|
|
}
|
174
|
|
|
175
|
45
|
public void setChainBuilder(ChainBuilder chainBuilder)
|
176
|
|
{
|
177
|
45
|
_chainBuilder = chainBuilder;
|
178
|
|
}
|
179
|
|
|
180
|
45
|
public void setGlobalProperties(IPropertySource globalProperties)
|
181
|
|
{
|
182
|
45
|
_globalProperties = globalProperties;
|
183
|
|
}
|
184
|
|
}
|