Package reportgen.prototype.context

Source Code of reportgen.prototype.context.ContextGeneric

package reportgen.prototype.context;

import java.util.ArrayList;
import java.util.LinkedList;
import reportgen.prototype.context.group.ContextGroup;
import java.util.List;
import reportgen.prototype.entity.QEntity;
import reportgen.prototype.entity.QEntityProperty;
import reportgen.math.reference.function.MathExpressionFunction;
import reportgen.prototype.columns.QueryResultColumn;
import reportgen.ren.executer.QueryExecuterSub;
import reportgen.ren.loader.SubQueryLoader;
import reportgen.math.reference.function.values.MathFunctionType;
import reportgen.math.reference.operator.MathExpressionOperatorRef;
import reportgen.math.reference.operator.variants.MOperator;
import reportgen.math.reference.operator.variants.binary.MathOperatorBinary;
import reportgen.math.agregate.agregate.AggregateFunction;
import reportgen.prototype.QCoreInlineSQL;
import reportgen.ren.report.column.ReportResultColumn;
import reportgen.ren.report.extendedformat.range.ColRowRange;
import reportgen.ren.report.extendedformat.range.cross.CrossReport;
import reportgen.ren.report.userinput.QueryInputValue;
import reportgen.utils.Atom;
import reportgen.utils.ReportException;

/**
* Контекст выражения
*/
public abstract class ContextGeneric implements  Context {

    private final AtomRegistrar ctx;

    public ContextGeneric(AtomRegistrar ctx) {
        this.ctx = ctx;
    }

    @Override
    public final void registerAtom(Atom atom) {
        ctx.registerAtom(atom);
    }

    @Override
    @Deprecated
    public SubQueryLoader getQueryLoader() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<ReportResultColumn> getReportResult() {
        return new ArrayList<ReportResultColumn>();
    }

    @Override
    final public ReportResultColumn getReportResult(String title) throws ReportException {
        for(ReportResultColumn column: getReportResult()) {
            if(column.getTitle().equals(title)) {
                return column;
            }
        }
        throw new ReportException("Результат отчета с идентификатором '" + title + "' не существует");
    }

    @Override
    public List<QEntity> getEntities(ContextGroup GROUP) {
        return new ArrayList<QEntity>();
    }

    @Override
    final public QEntity getEntity(Atom atom) throws ReportException {
        for(QEntity entity: getEntities(null)) {
            if(entity.getAtom().equals(atom)) {
                return entity;
            }
        }
        throw new ReportException("Сущность с идентификатором '" + atom + "' не существует");
    }

    @Override
    public List<QEntityProperty> getProperties(ContextGroup group, QEntity entity) {
        return new ArrayList<QEntityProperty>();
    }

    @Override
    final public QEntityProperty getProperty(ContextGroup group, QEntity entity, String name) throws ReportException {
        for(QEntityProperty property: getProperties(group, entity)) {
            if(property.getIdentification().equals(name)) {
                return property;
            }
        }
        throw new ReportException("Свойства с идентификатором '" + name + "' не существует");
    }


    @Override
    public List<QueryResultColumn> getQueryResults() {
        return new ArrayList<QueryResultColumn>();
    }

    @Override
    final public QueryResultColumn getQueryResults(String colTitle) throws ReportException {
        for(QueryResultColumn column: getQueryResults()) {
            if(column.getColTitle().equals(colTitle)) {
                return column;
            }
        }
        throw new ReportException("Результат выборки с идентификатором '" + colTitle + "' не существует");
    }

    @Override
    public List<QCoreInlineSQL> getInlines() {
        return new ArrayList<QCoreInlineSQL>();
    }

    @Override
    public QCoreInlineSQL getInline(Atom atom) throws ReportException {
        for(QCoreInlineSQL inline: getInlines()) {
            if(inline.getAtom().equals(atom)) {
                return inline;
            }
        }
        throw new ReportException("Подзапрос с идентификатором '" + atom + "' не существует");
    }


    @Override
    public List<QueryExecuterSub> getSubreports() {
        return new ArrayList<QueryExecuterSub>();
    }

    @Override
    final public QueryExecuterSub getSubreport(Atom atom) throws ReportException {
        for(QueryExecuterSub subreport: getSubreports()) {
            if(subreport.getAtom().equals(atom)) {
                return subreport;
            }
        }
        throw new ReportException("Подотчет с идентификатором '" + atom + "' не существует");
    }

    @Override
    public List<CrossReport> getCrossReports() {
        return new ArrayList<CrossReport>();
    }

    @Override
    final public CrossReport getCrossReport(Atom atom) throws ReportException {
        for(CrossReport crossreport: getCrossReports()) {
            if(crossreport.getAtom().equals(atom)) {
                return crossreport;
            }
        }
        throw new ReportException("Кросс-отчет с идентификатором '" + atom + "' не существует");
    }

    @Override
    public List<QueryInputValue> getInputs() {
        return new ArrayList<QueryInputValue>();
    }

    @Override
    final public QueryInputValue getInput(Atom atom) throws ReportException {
        for(QueryInputValue input: getInputs()) {
            if(input.getAtom().equals(atom)) {
                return input;
            }
        }
        throw new ReportException("Входное значение  с идентификатором '" + atom + "' не существует");
    }

    /**
     *
     * @return
     */
    @Override
    public List<AggregateFunction> getAggregFunctions(Class cls) {
        return new LinkedList<AggregateFunction>();
    }

    @Override
    final public AggregateFunction getAggregFunction(String mnemonic, Class cls) throws ReportException {
        for(AggregateFunction function: getAggregFunctions(cls)) {
            if(function.getMnemonic().equals(mnemonic)) {
                return function;
            }
        }
        throw new ReportException("Функции с идентификатором '" + mnemonic + "' не существует");
    }

    /**
     *
     * @return
     */
    @Override
    public List<MathFunctionType> getMathFunctions() {
        for(ContextGroup g: getAvailiableGroups()) {
            if(g.isTheSameType(MathExpressionFunction.GROUP)) {
                return MathFunctionType.getOptions(getContextMode() == ContextMode.SQL);
            }
        }
        return new ArrayList<MathFunctionType>();
    }

    @Override
    final public MathFunctionType getMathFunction(String mnemonic) throws ReportException {
        for(MathFunctionType func: getMathFunctions()) {
            if(func.getMnemonic().equals(mnemonic)) {
                return func;
            }
        }
        throw new ReportException("Функция  с идентификатором '" + mnemonic + "' не существует");
    }

    /**
     *
     * @return
     */
    @Override
    public List<MOperator> getOperators() {
        for(ContextGroup g: getAvailiableGroups()) {
            if(g.isTheSameType(MathExpressionOperatorRef.GROUP)) {
                return MathOperatorBinary.getOptions(
                        false,
                        getContextMode() == ContextMode.SQL
                );
            }
        }
        return new ArrayList<MOperator>();
    }

    @Override
    final public MOperator getOperator(String mnemonic) throws ReportException {
        for(MOperator operator: getOperators()) {
            if(operator.getMnemonic().trim().equals(mnemonic)) {
                return operator;
            }
        }
        throw new ReportException("Оператор  с идентификатором '" + mnemonic + "' не существует");
    }

    /**
     *
     * @return
     */
    @Override
    public List<ColRowRange> getRanges() {
        return new ArrayList<ColRowRange>();
    }

    @Override
    final public ColRowRange getRange(Atom atom) throws ReportException {
        for(ColRowRange range: getRanges()) {
            if(range.getAtom().equals(atom)) {
                return range;
            }
        }
        throw new ReportException("Диапазон с идентификатором '" + atom + "' не существует");

    }
}
TOP

Related Classes of reportgen.prototype.context.ContextGeneric

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.