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