ar.com.fdvs.dj.domain.DjBaseMMValueFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of DynamicJasper Show documentation
Show all versions of DynamicJasper Show documentation
DynamicJasper (DJ) is an API that hides the complexity of Jasper
Reports, it helps developers to save time when designing
simple/medium complexity reports generating the layout of the
report elements automatically. It creates reports dynamically,
defining at runtime the columns, column width (auto width), groups,
variables, fonts, charts, crosstabs, sub reports (that can also be dynamic), page size
and everything else that you can define at design time.
DJ keeps full compatibility with Jasper Reports since
it's a tool that helps create reports programmatically in
a easy way (it only interferes with the creation of the report
design doing the layout of the elements).
You can use the classic .jrxml files as templates while the
content and layout of the report elements are handled by the DJ
API.
http://dynamicjasper.com
package ar.com.fdvs.dj.domain;
import ar.com.fdvs.dj.core.DJException;
import java.util.Map;
/*
FDV Solutions
User: Juan Lagostena
Date: 12/20/11
*/
/**
* This class is like a ValueFormatter but with some tricks to get the values and names
* of all propertyMeasures in a crosstab
*/
public abstract class DjBaseMMValueFormatter implements DJValueFormatter {
private String[] propertyMeasures;
public Object evaluate(Object value, Map fields, Map variables, Map parameters) {
return innerEvaluate((Object[]) value, fields, variables, parameters);
}
public String[] getPropertyMeasures() {
return propertyMeasures;
}
public void setPropertyMeasures(String[] propertyMeasures) {
this.propertyMeasures = propertyMeasures;
}
public T getValueFor(Object[] values, String propertyMeasure) {
String measureName = null;
int idx = 0;
while (!propertyMeasure.equals(measureName) && idx < this.getPropertyMeasures().length) {
measureName = this.getPropertyMeasures()[idx];
idx++;
}
if (!propertyMeasure.equals(measureName)) {
throw new DJException("The measure " + propertyMeasure + " does not exist");
}
//noinspection unchecked
return (T) values[--idx];
}
protected abstract Object innerEvaluate(Object[] value, Map fields, Map variables, Map parameters);
}