/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package reportgen.ren.report.column;
import java.util.ArrayList;
import java.util.List;
import reportgen.prototype.context.ContextMode;
import reportgen.prototype.context.group.ContextGroup;
import reportgen.math.agregate.simpleformat.SimpleFormatColMode;
import reportgen.math.agregate.agregate.AggregateFunction;
import reportgen.math.ResultColumn;
import reportgen.utils.SupportXMLRootImpl;
import org.jdom.Element;
import reportgen.prototype.context.Context;
import reportgen.prototype.context.ContextGeneric;
import reportgen.prototype.context.NoNeedAtom;
import reportgen.utils.ReportException;
/**
* @author axe
*/
public class ReportResultColumn extends SupportXMLRootImpl {
public static final String TAGNAME = "resultvalue";
public static final String ATTR_VIEWFUNCTION = "view";
public static final String ATTR_CLASS = "cls";
public static final String ATTR_DESC = "desc";
private final Context context;
private final ResultColumn properties;
private AggregateFunction viewFunction = AggregateFunction.ASIS;
private Class colClass;
private String description = "";
public ReportResultColumn(Context context) {
properties = new ResultColumn();
this.context = context;
}
public ReportResultColumn(Element element, Context context) throws ReportException {
this.context = context;
description = getStringAttribute(element, ATTR_DESC, "", false);
colClass = null;
String cls = null;
try {
cls = getStringAttribute(element, ATTR_CLASS);
if (cls.length() == 0) {
throw new ReportException("Не указан класс результирующей колонки");
}
colClass = getClass().getClassLoader().loadClass(cls);
} catch (ClassNotFoundException ex) {
throw new ReportException("Класс результирующей колонки имеет неизвестный тип:" + cls);
}
properties = new ResultColumn(element, context, colClass);
String viewFuncVal = getStringAttribute(element, ATTR_VIEWFUNCTION, null, false);
if(viewFuncVal != null) {
viewFunction = SimpleFormatColMode.fromName(viewFuncVal);
} else {
viewFunction = AggregateFunction.ASIS;
}
}
@Override
protected void toXML(Element root) {
root.setAttribute(ATTR_CLASS, colClass.getName());
if(viewFunction != AggregateFunction.ASIS) {
root.setAttribute(ATTR_VIEWFUNCTION, viewFunction.getMnemonic());
}
if(description.length() > 0) {
root.setAttribute(ATTR_DESC, description);
}
properties.toXML(root);
}
@Override
protected String getRootTag() {
return TAGNAME;
}
public ResultColumn getProperties() {
return properties;
}
public Context getContext() {
return context;
}
/**
* Get the value of colTitle
*
* @return the value of colTitle
*/
public String getTitle() {
return properties.getColTitle();
}
public AggregateFunction getViewFunction() {
return viewFunction;
}
public void setViewFunction(AggregateFunction viewFunction) {
this.viewFunction = viewFunction;
}
/**
* Set the value of colTitle
*
* @param colTitle new value of colTitle
*/
public void setTitle(String colTitle) {
properties.setColTitle(colTitle);
}
public AggregateFunction getFunction() {
return properties.getFunction();
}
public void setFunction(AggregateFunction function) {
properties.setFunction(function);
}
public int getOrderPriority() {
return properties.getOrderPriority();
}
public void setOrderPriority(int orderPriority) {
properties.setOrderPriority(orderPriority);
}
public Class getCls() throws ReportException {
return properties.getFunction().getResultClass(colClass);
}
public Class getColClass() {
return colClass;
}
public void setColClass(Class colClass) {
this.colClass = colClass;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
if(properties.getColTitle() == null || properties.getColTitle().length()==0) {
return super.toString();
}
return "[" + properties.getColTitle() + "]";
}
}