Package reportgen.cores.ejb

Source Code of reportgen.cores.ejb.CoreInline

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package reportgen.cores.ejb;

import java.util.HashSet;
import java.util.Set;
import org.jdom.Element;
import reportgen.math.complex.inlineresult.MathExpressionInlineResult;
import reportgen.prototype.QCoreInline;
import reportgen.prototype.UsedReportableType;
import reportgen.prototype.context.Context;
import reportgen.prototype.entity.QEntityProperty;
import reportgen.utils.Atom;
import reportgen.utils.ReportException;

/**
*
* @author axe
*/
abstract class CoreInline extends AbstractCore implements QCoreInline {

    private final MathExpressionInlineResult result;
    private Atom atom;

    public CoreInline(String title, Context context) {
        super(title, context);
        atom = new Atom();
        result = new MathExpressionInlineResult(getCoreContext());
    }

    public CoreInline(Element element, Context context) throws ReportException {
        super(element, context);
        atom = new Atom(element, context);

        MathExpressionInlineResult loadResult = null;
        Element resultsEl = element.getChild(MathExpressionInlineResult.TAG);
        if (resultsEl != null) {
            loadResult = new MathExpressionInlineResult(resultsEl, getCoreContext());
        } else {
            throw new ReportException("Отсутствует результат подзапроса");
        }
        result = loadResult;
    }


    @Override
    protected void toXML(Element root) {
        super.toXML(root);
        atom.toXML(root);
        root.addContent(result.toXML());
    }

    @Override
    public String toString() {
        return "Подзапрос:" + getTitle();
    }

    @Override
    public void ensureSafeRemove(Object obj2remove) throws ReportException {
        super.ensureSafeRemove(obj2remove);
        if (result.isContain(obj2remove)) {
            throw new ReportException("Нельзя удалить этот элемент, ссылка на него содержится в"
                    + " результатках подзапроса");
        }
    }

    @Override
    public Atom getAtom() {
        return atom;
    }

    @Override
    protected Set<QEntityProperty> getLoadable() {
        Set<QEntityProperty> props = new HashSet<QEntityProperty>();
        result.buildUsedSet(UsedReportableType.property, props);
        return props;
    }

    @Override
    public MathExpressionInlineResult getResult() {
        return result;
    }

    @Override
    public void validate() throws ReportException {
        if (result.isEmpty()) {
            throw new ReportException("Не выбран результат подзапроса");
        }
    }

    /**
     * Local core context may be SQL or another, in dependency of choosen
     * inline core type
     * @return
     */
    protected abstract Context getCoreContext();
}
TOP

Related Classes of reportgen.cores.ejb.CoreInline

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.