01: /*
02: * Copyright 2004 Sun Microsystems, Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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,
34: BaseWireFeedGenerator parentGenerator) {
35: super (propertyKey, null, parentGenerator);
36: }
37:
38: public ModuleGenerator getGenerator(String uri) {
39: return (ModuleGenerator) getPlugin(uri);
40: }
41:
42: protected String getKey(Object obj) {
43: return ((ModuleGenerator) obj).getNamespaceUri();
44: }
45:
46: public List getModuleNamespaces() {
47: return getKeys();
48: }
49:
50: public void generateModules(List modules, Element element) {
51: Map generators = getPluginMap();
52: for (int i = 0; i < modules.size(); i++) {
53: Module module = (Module) modules.get(i);
54: String namespaceUri = module.getUri();
55: ModuleGenerator generator = (ModuleGenerator) generators
56: .get(namespaceUri);
57: if (generator != null) {
58: generator.generate(module, element);
59: }
60: }
61: }
62:
63: public Set getAllNamespaces() {
64: if (_allNamespaces == null) {
65: _allNamespaces = new HashSet();
66: List mUris = getModuleNamespaces();
67: for (int i = 0; i < mUris.size(); i++) {
68: ModuleGenerator mGen = getGenerator((String) mUris
69: .get(i));
70: _allNamespaces.addAll(mGen.getNamespaces());
71: }
72: }
73: return _allNamespaces;
74: }
75: }
|