Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2022 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.query;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JRValueParameter;
import net.sf.jasperreports.engine.util.Pair;
/**
* @author Lucian Chirita ([email protected])
*/
public class ParameterTypeSelectorClauseFunction implements JRClauseFunction
{
private static final Log log = LogFactory.getLog(ParameterTypeSelectorClauseFunction.class);
public static final String EXCEPTION_MESSAGE_KEY_QUERY_PARAMETER_TYPE_SELECTOR_CLAUSE_IMPLEMENTATION_NOT_FOUND = "query.parameter.type.selector.clause.implementation.not.found";
public static final String EXCEPTION_MESSAGE_KEY_QUERY_PARAMETER_TYPE_SELECTOR_CLAUSE_REQUIRED_TOKEN_NOT_FOUND = "query.parameter.type.selector.clause.required.token.not.found";
private static final String CONTEXT_KEY_FUNCTION_PER_TYPES_CACHE =
"net.sf.jasperreports.engine.query.ParameterTypeSelectorClauseFunction.cache";
private final int[] parameterPositions;
public ParameterTypeSelectorClauseFunction(int ... parameterPositions)
{
this.parameterPositions = parameterPositions;
}
@Override
public void apply(JRClauseTokens clauseTokens, JRQueryClauseContext queryContext)
{
List> parameterTypes = new ArrayList<>(parameterPositions.length);
for (int position : parameterPositions)
{
Class parameterType = determineParameterType(clauseTokens,
queryContext, position);
parameterTypes.add(parameterType);
}
JRClauseFunction function = getForParameterTypes(clauseTokens, queryContext, parameterTypes);
if (function == null)
{
throw
new JRRuntimeException(
EXCEPTION_MESSAGE_KEY_QUERY_PARAMETER_TYPE_SELECTOR_CLAUSE_IMPLEMENTATION_NOT_FOUND,
new Object[]{clauseTokens.getClauseId(), parameterTypes});
}
function.apply(clauseTokens, queryContext);
}
protected Class determineParameterType(JRClauseTokens clauseTokens,
JRQueryClauseContext queryContext, int parameterPosition)
{
String parameterName = clauseTokens.getToken(parameterPosition);
if (parameterName == null)
{
throw
new JRRuntimeException(
EXCEPTION_MESSAGE_KEY_QUERY_PARAMETER_TYPE_SELECTOR_CLAUSE_IMPLEMENTATION_NOT_FOUND,
new Object[]{parameterPosition, clauseTokens.getClauseId()});
}
// the method throws an exception if it doesn't find the parameter,
// so we don't have to handle that case here
JRValueParameter parameter = queryContext.getValueParameter(parameterName);
Class parameterType;
Object parameterValue = parameter.getValue();
if (parameterValue == null)
{
// if we don't have a value, use the declared type
parameterType = parameter.getValueClass();
}
else
{
// use the actual value
parameterType = parameterValue.getClass();
}
if (log.isDebugEnabled())
{
log.debug("query clause parameter " + parameterName
+ " at position " + parameterPosition
+ " has type " + parameterType.getName());
}
return parameterType;
}
protected JRClauseFunction getForParameterTypes(JRClauseTokens clauseTokens,
JRQueryClauseContext queryContext, List> parameterTypes)
{
Map