/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program 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.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors.. All rights reserved.
*/
package org.pentaho.reporting.engine.classic.core.parameters;
import org.pentaho.reporting.engine.classic.core.AttributeNames;
import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.DataRow;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.ReportDataFactoryException;
import org.pentaho.reporting.engine.classic.core.ReportEnvironment;
import org.pentaho.reporting.engine.classic.core.ReportEnvironmentDataRow;
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
import org.pentaho.reporting.engine.classic.core.ResourceBundleFactory;
import org.pentaho.reporting.engine.classic.core.cache.CachingDataFactory;
import org.pentaho.reporting.engine.classic.core.util.ReportParameterValues;
import org.pentaho.reporting.libraries.base.config.Configuration;
import org.pentaho.reporting.libraries.docbundle.DocumentBundle;
import org.pentaho.reporting.libraries.docbundle.DocumentMetaData;
import org.pentaho.reporting.libraries.resourceloader.ResourceKey;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
/**
* Todo: Document me!
*
* @author : Thomas Morgner
*/
public class DefaultParameterContext implements ParameterContext
{
private ReportEnvironment reportEnvironment;
private CompoundDataRow parameterValues;
private ResourceBundleFactory resourceBundleFactory;
private Configuration configuration;
private CachingDataFactory dataFactory;
private ResourceKey contentBase;
private ResourceManager resourceManager;
private DocumentMetaData documentMetaData;
private ReportEnvironmentDataRow envDataRow;
public DefaultParameterContext(final MasterReport report) throws ReportProcessingException
{
this(report, report.getParameterValues());
}
public DefaultParameterContext(final MasterReport report,
final ReportParameterValues parameterValues) throws ReportProcessingException
{
if (report == null)
{
throw new NullPointerException("Report parameter must not be null");
}
if (parameterValues == null)
{
throw new NullPointerException("ParameterValues parameter must not be null");
}
this.configuration = report.getConfiguration();
this.resourceBundleFactory = MasterReport.computeAndInitResourceBundleFactory
(report.getResourceBundleFactory(), report.getReportEnvironment());
this.contentBase = report.getContentBase();
this.resourceManager = report.getResourceManager();
this.reportEnvironment = report.getReportEnvironment();
final Object dataCacheEnabledRaw =
report.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.DATA_CACHE);
final boolean dataCacheEnabled = Boolean.FALSE.equals(dataCacheEnabledRaw) == false;
this.dataFactory = new CachingDataFactory(report.getDataFactory(), dataCacheEnabled);
final DocumentBundle bundle = report.getBundle();
if (bundle != null)
{
this.documentMetaData = bundle.getMetaData();
}
this.dataFactory.initialize(configuration, resourceManager, contentBase, resourceBundleFactory);
final ReportEnvironmentDataRow envDataRow = new ReportEnvironmentDataRow(reportEnvironment);
this.parameterValues = new CompoundDataRow(envDataRow, parameterValues);
}
public DefaultParameterContext(final DataFactory dataFactory,
final DataRow parameterValues,
final Configuration configuration,
final ResourceBundleFactory resourceBundleFactory,
final ResourceManager resourceManager,
final ResourceKey resourceKey,
final ReportEnvironment reportEnvironment)
{
this.configuration = configuration;
this.resourceBundleFactory = resourceBundleFactory;
this.resourceManager = resourceManager;
this.contentBase = resourceKey;
this.reportEnvironment = reportEnvironment;
this.dataFactory = new CachingDataFactory(dataFactory, false);
this.dataFactory.initialize(configuration, resourceManager, resourceKey, resourceBundleFactory);
this.envDataRow = new ReportEnvironmentDataRow(reportEnvironment);
this.parameterValues = new CompoundDataRow(envDataRow, parameterValues);
}
public DocumentMetaData getDocumentMetaData()
{
return documentMetaData;
}
public ReportEnvironment getReportEnvironment()
{
return reportEnvironment;
}
public ResourceManager getResourceManager()
{
return resourceManager;
}
public Configuration getConfiguration()
{
return configuration;
}
public void open() throws ReportDataFactoryException
{
this.dataFactory.open();
}
public DataRow getParameterData()
{
return parameterValues;
}
public DataRow getParameterValues()
{
return parameterValues.getDataRow();
}
public void setParameterValues(final DataRow parameterValues)
{
if (parameterValues == null)
{
throw new NullPointerException();
}
this.parameterValues = new CompoundDataRow(envDataRow, parameterValues);
}
public DataFactory getDataFactory()
{
return dataFactory;
}
public ResourceBundleFactory getResourceBundleFactory()
{
return resourceBundleFactory;
}
public void close() throws ReportDataFactoryException
{
this.dataFactory.close();
}
public ResourceKey getContentBase()
{
return contentBase;
}
}