/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package reportgen.prototype.columns;
import java.util.Set;
import reportgen.math.agregate.agregate.AggregateFunction;
import org.jdom.Element;
import reportgen.prototype.context.Context;
import reportgen.utils.ReportException;
import reportgen.math.ExpressionContainer;
import reportgen.math.ResultColumn;
import reportgen.prototype.UsedReportable;
import reportgen.math.complex.generic.MathExpressionGeneric;
import reportgen.prototype.UsedReportableType;
import reportgen.utils.SupportXMLRootImpl;
/**
* @author axe
*/
public class QueryResultColumn extends SupportXMLRootImpl
implements ExpressionContainer, UsedReportable {
public static final String TAG = "column";
private final ResultColumn properties;
private final MathExpressionGeneric expression;
private final Context context;
public QueryResultColumn(Context context) {
this.context = context;
properties = new ResultColumn();
expression = new MathExpressionGeneric(context);
}
public QueryResultColumn(Element element, Context context) throws ReportException {
this.context = context;
expression = new MathExpressionGeneric(
get(element, MathExpressionGeneric.TAG),
context
);
properties = new ResultColumn(element, context, expression.getCls());
}
@Override
protected void toXML(Element root) {
properties.toXML(root);
root.addContent(expression.toXML());
}
public Context getContext() {
return context;
}
@Override
protected String getRootTag() {
return TAG;
}
public ResultColumn getProperty() {
return properties;
}
public String getColTitle() {
return properties.getColTitle();
}
public void setColTitle(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 MathExpressionGeneric getExpression() {
return expression;
}
@Override
public boolean isContain(Object obj) {
return expression.isContain(obj);
}
@Override
public void validate() throws ReportException {
expression.validate();
}
public Class getCls() throws ReportException {
return expression.getCls();
}
@Override
public void buildUsedSet(UsedReportableType cls, Set set) {
expression.buildUsedSet(cls, set);
}
@Override
public String toString() {
if(properties.getColTitle() == null || properties.getColTitle().length()==0) {
return super.toString();
}
return "[" + properties.getColTitle() + "]";
}
}