View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package com.sun.syndication.io.impl;
18  
19  import com.sun.syndication.feed.module.Module;
20  import com.sun.syndication.io.ModuleGenerator;
21  import org.jdom.Element;
22  
23  import java.util.HashSet;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.Set;
27  
28  /**
29   */
30  public class ModuleGenerators extends PluginManager {
31      private Set _allNamespaces;
32  
33      public ModuleGenerators(String propertyKey, BaseWireFeedGenerator parentGenerator) {
34          super(propertyKey, null, parentGenerator);
35      }
36  
37      public ModuleGenerator getGenerator(String uri) {
38          return (ModuleGenerator) getPlugin(uri);
39      }
40  
41      protected String getKey(Object obj) {
42          return ((ModuleGenerator)obj).getNamespaceUri();
43      }
44  
45      public List getModuleNamespaces() {
46          return getKeys();
47      }
48  
49      public void generateModules(List modules, Element element) {
50          Map generators = getPluginMap();
51          for (int i = 0; i < modules.size(); i++) {
52              Module module = (Module) modules.get(i);
53              String namespaceUri = module.getUri();
54              ModuleGenerator generator = (ModuleGenerator)generators.get(namespaceUri);
55              if (generator != null) {
56                  generator.generate(module, element);
57              }
58          }
59      }
60  
61      public Set getAllNamespaces() {
62          if (_allNamespaces==null) {
63              _allNamespaces = new HashSet();
64              List mUris = getModuleNamespaces();
65              for (int i=0;i<mUris.size();i++) {
66                  ModuleGenerator mGen = getGenerator((String)mUris.get(i));
67                  _allNamespaces.addAll(mGen.getNamespaces());
68              }
69          }
70          return _allNamespaces;
71      }
72  }