1 /*
2 * JasperReports - Free Java Reporting Library.
3 * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4 * http://www.jaspersoft.com
5 *
6 * Unless you have purchased a commercial license agreement from Jaspersoft,
7 * the following license terms apply:
8 *
9 * This program is part of JasperReports.
10 *
11 * JasperReports is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * JasperReports is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23 */
24 package net.sf.jasperreports.engine.component;
25
26 import java.util.Map;
27 import java.util.Set;
28
29 import net.sf.jasperreports.engine.JRRuntimeException;
30
31 /**
32 * The default {@link ComponentsBundle components bundle} implementation.
33 *
34 * <p>
35 * A components bundle consists of a {@link ComponentsXmlParser XML parser}
36 * instance and a map of {@link ComponentManager component managers}.
37 *
38 * @author Lucian Chirita (lucianc@users.sourceforge.net)
39 */
40 public class DefaultComponentsBundle implements ComponentsBundle
41 {
42
43 private ComponentsXmlParser xmlParser;
44 private Map<String,ComponentManager> componentManagers;
45
46 public static final String EXCEPTION_MESSAGE_KEY_COMPONENT_MANAGER_NOT_FOUND = "components.component.manager.not.found";
47
48 @Override
49 public ComponentsXmlParser getXmlParser()
50 {
51 return xmlParser;
52 }
53
54 /**
55 * Sets the components XML parser implementation.
56 *
57 * @param xmlParser the components XML parser
58 * @see #getXmlParser()
59 */
60 public void setXmlParser(ComponentsXmlParser xmlParser)
61 {
62 this.xmlParser = xmlParser;
63 }
64
65 @Override
66 public Set<String> getComponentNames()
67 {
68 return componentManagers.keySet();
69 }
70
71 @Override
72 public ComponentManager getComponentManager(String componentName)
73 {
74 ComponentManager manager = componentManagers.get(componentName);
75 if (manager == null)
76 {
77 throw
78 new JRRuntimeException(
79 EXCEPTION_MESSAGE_KEY_COMPONENT_MANAGER_NOT_FOUND,
80 new Object[]{componentName, xmlParser.getNamespace()});
81 }
82 return manager;
83 }
84
85 /**
86 * Returns the internal map of component managers, indexed by component name.
87 *
88 * @return the map of component managers
89 * @see #setComponentManagers(Map)
90 */
91 public Map<String,ComponentManager> getComponentManagers()
92 {
93 return componentManagers;
94 }
95
96 /**
97 * Sets the map of component managers.
98 *
99 * <p>
100 * The map needs to use component names as keys, and {@link ComponentManager}
101 * instances as values.
102 *
103 * @param componentManagers the map of component managers
104 */
105 public void setComponentManagers(Map<String,ComponentManager> componentManagers)
106 {
107 this.componentManagers = componentManagers;
108 }
109
110 }
111