View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.doxia.parser.module;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  import javax.inject.Singleton;
24  
25  import java.util.Collection;
26  import java.util.LinkedHashMap;
27  import java.util.Map;
28  
29  /**
30   * Simple implementation of the ParserModuleManager interface.
31   *
32   * @since 1.6
33   */
34  @Singleton
35  @Named
36  public class DefaultParserModuleManager implements ParserModuleManager {
37      @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
38      @Inject
39      private Map<String, ParserModule> parserModules;
40  
41      private Collection<ParserModule> parserModulesValues;
42  
43      /**
44       * {@inheritDoc}
45       *
46       * @return a {@link java.util.Collection} object.
47       */
48      public Collection<ParserModule> getParserModules() {
49          if (parserModulesValues == null) {
50              Map<Class<?>, ParserModule> parserModulesTmp = new LinkedHashMap<>();
51              for (ParserModule module : parserModules.values()) {
52                  parserModulesTmp.put(module.getClass(), module);
53              }
54              parserModulesValues = parserModulesTmp.values();
55          }
56  
57          return parserModulesValues;
58      }
59  
60      /** {@inheritDoc} */
61      public ParserModule getParserModule(String id) throws ParserModuleNotFoundException {
62          ParserModule parserModule = parserModules.get(id);
63  
64          if (parserModule == null) {
65              throw new ParserModuleNotFoundException("Cannot find parser module id '" + id + "'");
66          }
67  
68          return parserModule;
69      }
70  }