1/*2 * $Id: BasicPatternDefinitionResolver.java 836180 2009-11-14 14:00:02Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122package org.apache.tiles.definition.pattern;
2324import java.util.LinkedHashSet;
25import java.util.List;
26import java.util.Map;
27import java.util.Set;
2829import org.apache.tiles.Definition;
3031/**32 * A pattern definition resolver that stores {@link DefinitionPatternMatcher}33 * separated by customization key. <br>34 * It delegates creation of definition pattern matchers to a35 * {@link DefinitionPatternMatcherFactory} and recgnizes patterns through the36 * use of a {@link PatternRecognizer}.37 *38 * @param <T> The type of the customization key.39 * @version $Rev: 836180 $ $Date: 2009-11-15 01:00:02 +1100 (Sun, 15 Nov 2009) $40 * @since 2.2.041 */42publicclass BasicPatternDefinitionResolver<T> extends43 AbstractPatternDefinitionResolver<T> {
4445/**46 * The factory of pattern matchers.47 */48privateDefinitionPatternMatcherFactory definitionPatternMatcherFactory;
4950/**51 * The pattern recognizer.52 */53privatePatternRecognizer patternRecognizer;
5455/**56 * Constructor.57 *58 * @param definitionPatternMatcherFactory The definition pattern matcher factory.59 * @param patternRecognizer The pattern recognizer.60 */61publicBasicPatternDefinitionResolver(DefinitionPatternMatcherFactory definitionPatternMatcherFactory,
62PatternRecognizer patternRecognizer) {
63this.definitionPatternMatcherFactory = definitionPatternMatcherFactory;
64this.patternRecognizer = patternRecognizer;
65 }
6667/** {@inheritDoc} */68 @Override
69protected Map<String, Definition> addDefinitionsAsPatternMatchers(List<DefinitionPatternMatcher> matchers,
70 Map<String, Definition> defsMap) {
71 Set<String> excludedKeys = new LinkedHashSet<String>();
72for (Map.Entry<String, Definition> de : defsMap.entrySet()) {
73 String key = de.getKey();
74if (patternRecognizer.isPatternRecognized(key)) {
75 matchers.add(definitionPatternMatcherFactory
76 .createDefinitionPatternMatcher(key, de.getValue()));
77 } else {
78 excludedKeys.add(key);
79 }
80 }
81return PatternUtil.createExtractedMap(defsMap, excludedKeys);
82 }
83 }