001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.olap;
029:
030: import java.util.Map;
031:
032: import net.sf.jasperreports.engine.JRDataset;
033: import net.sf.jasperreports.engine.JRException;
034: import net.sf.jasperreports.engine.JRValueParameter;
035: import net.sf.jasperreports.engine.query.JREmptyQueryExecuter;
036: import net.sf.jasperreports.engine.query.JRQueryExecuter;
037: import net.sf.jasperreports.engine.query.JRQueryExecuterFactory;
038: import net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter;
039: import net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuterFactory;
040:
041: import org.apache.commons.logging.Log;
042: import org.apache.commons.logging.LogFactory;
043:
044: /**
045: * @author Lucian Chirita (lucianc@users.sourceforge.net)
046: * @version $Id: JRMdxQueryExecuterFactory.java 1575 2007-02-08 16:53:46Z lucianc $
047: */
048: public class JRMdxQueryExecuterFactory implements
049: JRQueryExecuterFactory {
050:
051: private static final Log log = LogFactory
052: .getLog(JRMdxQueryExecuterFactory.class);
053:
054: private final static Object[] MDX_BUILTIN_PARAMETERS;
055:
056: static {
057: Object[] mondrianParams = new JRMondrianQueryExecuterFactory()
058: .getBuiltinParameters();
059: Object[] xmlaParams = new JRXmlaQueryExecuterFactory()
060: .getBuiltinParameters();
061:
062: MDX_BUILTIN_PARAMETERS = new Object[mondrianParams.length
063: + xmlaParams.length];
064: System.arraycopy(mondrianParams, 0, MDX_BUILTIN_PARAMETERS, 0,
065: mondrianParams.length);
066: System.arraycopy(xmlaParams, 0, MDX_BUILTIN_PARAMETERS,
067: mondrianParams.length, xmlaParams.length);
068: }
069:
070: public Object[] getBuiltinParameters() {
071: return MDX_BUILTIN_PARAMETERS;
072: }
073:
074: public JRQueryExecuter createQueryExecuter(JRDataset dataset,
075: Map parameters) throws JRException {
076: JRQueryExecuter queryExecuter;
077: if (getParameterValue(
078: parameters,
079: JRMondrianQueryExecuterFactory.PARAMETER_MONDRIAN_CONNECTION) != null) {
080: queryExecuter = new JRMondrianQueryExecuter(dataset,
081: parameters);
082: } else if (getParameterValue(parameters,
083: JRXmlaQueryExecuterFactory.PARAMETER_XMLA_URL) != null) {
084: queryExecuter = new JRXmlaQueryExecuter(dataset, parameters);
085: } else {
086: log
087: .warn("No Mondrian connection or XMLA URL set for MDX query");
088: queryExecuter = new JREmptyQueryExecuter();
089: }
090: return queryExecuter;
091: }
092:
093: protected final Object getParameterValue(Map valueParams,
094: String name) {
095: JRValueParameter valueParam = (JRValueParameter) valueParams
096: .get(name);
097: return valueParam == null ? null : valueParam.getValue();
098: }
099:
100: public boolean supportsQueryParameterType(String className) {
101: return true;
102: }
103:
104: }
|