All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jasperreports.engine.export.DefaultElementHandlerBundle Maven / Gradle / Ivy

There is a newer version: 6.21.2
Show newest version
/*
 * JasperReports - Free Java Reporting Library.
 * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
 * http://www.jaspersoft.com
 *
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 * the following license terms apply:
 *
 * This program is part of JasperReports.
 *
 * JasperReports is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JasperReports is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JasperReports. If not, see .
 */
package net.sf.jasperreports.engine.export;

import java.util.Map;

import net.sf.jasperreports.engine.JRRuntimeException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * The default {@link GenericElementHandlerBundle} implementation.
 * 
 * 

* This implementation uses a {@link Map map} to keep element handlers. * * @author Lucian Chirita ([email protected]) */ public class DefaultElementHandlerBundle implements GenericElementHandlerBundle { private static final Log log = LogFactory.getLog(DefaultElementHandlerBundle.class); public static final String EXCEPTION_MESSAGE_KEY_HANDLERS_NOT_FOUND_FOR_TYPE = "export.common.handlers.not.found.for.type"; private String namespace; private Map> elementHandlers; /** * Uses the handler map to locate a handler for the element name * and exporter key. * * @throws JRRuntimeException if no handler is found */ @Override public GenericElementHandler getHandler(String elementName, String exporterKey) { Map handlers = elementHandlers.get(elementName); if (handlers == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_HANDLERS_NOT_FOUND_FOR_TYPE, new Object[]{namespace, elementName}); } GenericElementHandler handler = handlers.get(exporterKey); if (handler == null && log.isDebugEnabled()) { log.debug("No " + exporterKey + " handler for generic elements of type " + namespace + "#" + elementName); } return handler; } @Override public String getNamespace() { return namespace; } /** * Sets the namespace of this bundle. * * @param namespace the namespace * @see #getNamespace() */ public void setNamespace(String namespace) { this.namespace = namespace; } /** * Returns the map of element handlers. * * @return the map of element handlers */ public Map> getElementHandlers() { return elementHandlers; } /** * Sets the map of element handlers. * *

* The map needs to be a two level map, the first one indexed by element * names and the second level indexed by exporter keys. * * @param elementHandlers the map of element handlers */ public void setElementHandlers(Map> elementHandlers) { this.elementHandlers = elementHandlers; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy