1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.definition.pattern;
23
24 import java.util.LinkedHashSet;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.apache.tiles.Definition;
30
31 /***
32 * A pattern definition resolver that stores {@link DefinitionPatternMatcher}
33 * separated by customization key. <br>
34 * It delegates creation of definition pattern matchers to a
35 * {@link DefinitionPatternMatcherFactory} and recgnizes patterns through the
36 * use of a {@link PatternRecognizer}.
37 *
38 * @param <T> The type of the customization key.
39 * @version $Rev: 823662 $ $Date: 2009-10-09 20:48:03 +0200 (ven, 09 ott 2009) $
40 * @since 2.2.0
41 */
42 public class BasicPatternDefinitionResolver<T> extends
43 AbstractPatternDefinitionResolver<T> {
44
45 /***
46 * The factory of pattern matchers.
47 */
48 private DefinitionPatternMatcherFactory definitionPatternMatcherFactory;
49
50 /***
51 * The pattern recognizer.
52 */
53 private PatternRecognizer patternRecognizer;
54
55 /***
56 * Constructor.
57 *
58 * @param definitionPatternMatcherFactory The definition pattern matcher factory.
59 * @param patternRecognizer The pattern recognizer.
60 */
61 public BasicPatternDefinitionResolver(DefinitionPatternMatcherFactory definitionPatternMatcherFactory,
62 PatternRecognizer patternRecognizer) {
63 this.definitionPatternMatcherFactory = definitionPatternMatcherFactory;
64 this.patternRecognizer = patternRecognizer;
65 }
66
67 /*** {@inheritDoc} */
68 protected Map<String, Definition> addDefinitionsAsPatternMatchers(List<DefinitionPatternMatcher> matchers,
69 Map<String, Definition> defsMap) {
70 Set<String> excludedKeys = new LinkedHashSet<String>();
71 for (Map.Entry<String, Definition> de : defsMap.entrySet()) {
72 String key = de.getKey();
73 if (patternRecognizer.isPatternRecognized(key)) {
74 matchers.add(definitionPatternMatcherFactory
75 .createDefinitionPatternMatcher(key, de.getValue()));
76 } else {
77 excludedKeys.add(key);
78 }
79 }
80 return PatternUtil.createExtractedMap(defsMap, excludedKeys);
81 }
82 }