1 package org.apache.maven.doxia.module.site.manager;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.Collection;
23 import java.util.LinkedHashMap;
24 import java.util.Map;
25
26 import org.apache.maven.doxia.module.site.SiteModule;
27
28 /**
29 * Simple implementation of the SiteModuleManager interface.
30 *
31 * @author Jason van Zyl
32 * @version $Id: DefaultSiteModuleManager.java 1090706 2011-04-09 23:15:28Z hboutemy $
33 * @since 1.0
34 * @plexus.component
35 */
36 public class DefaultSiteModuleManager
37 implements SiteModuleManager
38 {
39 /**
40 * @plexus.requirement role="org.apache.maven.doxia.module.site.SiteModule"
41 */
42 private Map<String, SiteModule> siteModules;
43
44 private Collection<SiteModule> siteModulesValues;
45
46 /** {@inheritDoc} */
47 public Collection<SiteModule> getSiteModules()
48 {
49 if ( siteModulesValues == null )
50 {
51 Map<Class<?>, SiteModule> siteModulesTmp = new LinkedHashMap<Class<?>, SiteModule>();
52 for ( SiteModule module : siteModules.values() )
53 {
54 siteModulesTmp.put( module.getClass(), module );
55 }
56 siteModulesValues = siteModulesTmp.values();
57 }
58
59 return siteModulesValues;
60 }
61
62 /** {@inheritDoc} */
63 public SiteModule getSiteModule( String id )
64 throws SiteModuleNotFoundException
65 {
66 SiteModule siteModule = siteModules.get( id );
67
68 if ( siteModule == null )
69 {
70 throw new SiteModuleNotFoundException( "Cannot find site module id = " + id );
71 }
72
73 return siteModule;
74 }
75 }