Package reportgen.math.reference.method

Source Code of reportgen.math.reference.method.MathExpressionEntityMethodRef

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

package reportgen.math.reference.method;


import java.util.Map;
import reportgen.prototype.stream.SQLStream;
import reportgen.utils.ReportException;
import java.util.Set;
import org.jdom.Element;
import reportgen.prototype.context.group.ContextGroup;
import reportgen.prototype.context.Context;
import reportgen.prototype.entity.QEntity;
import reportgen.prototype.entity.QEntityProperty;
import reportgen.math.MathExpressionOperand;
import reportgen.prototype.UsedReportableType;
import reportgen.utils.Atom;

/**
*
* @author axe
*/

public class MathExpressionEntityMethodRef extends MathExpressionOperand {

    public static final MethodContextGroup GROUP = new MethodContextGroup();
    public static final String TAG = "method";
    public static final String ATTR_VALUE = "value";
    private QEntityProperty property;

    public MathExpressionEntityMethodRef(QEntityProperty property, Context context) {
        super(context);
        this.property = property;
    }

   public MathExpressionEntityMethodRef(Element element, Context context) throws ReportException {
        super(element, context);
        String fullname = getStringAttribute(element, ATTR_VALUE);
        int aliaspos = fullname.indexOf('.');
        Atom atom = new Atom(fullname.substring(0, aliaspos));
        QEntity entity =  context.getEntity(atom);

        String propertyName = fullname.substring(aliaspos+1);
        ContextGroup contextGroup = getContextGroup(entity.getContextGroup());
        property = context.getProperty(contextGroup, entity, propertyName);
    }

    @Override
    protected void toXML(Element root) {
        String mnemonic = property.getEntity().getAtom() + "." + property.getIdentification();
        root.setAttribute(ATTR_VALUE, mnemonic);
    }

    @Override
    public MathExpressionEntityMethodRef makeClone() throws ReportException {
        return new MathExpressionEntityMethodRef(toXML(), getParentContext());
    }

    @Override
    public MethodContextGroup getContextGroup() {
        return getContextGroup(property.getEntity().getContextGroup());
    }

   
    @Override
    protected String getRootTag() {
        return TAG;
    }

    public static MethodContextGroup getContextGroup(ContextGroup coreGroup) {
        return (MethodContextGroup) GROUP.clone(coreGroup);
    }

    @Override
    public Class getCls() {
        return getRef().getCls();
    }

    public QEntityProperty getRef() {
        return property;
    }

    public void setRef(QEntityProperty property) {
        this.property = property;
    }

    @Override
    public String toString() {
        return property.toString();
    }

    @Override
    public void validate() throws ReportException {
        if(property == null) {
            throw new ReportException("Не выбрано свойство объекта");
        }
    }

    @Override
    public boolean isContain(Object entity) {
        if(property == entity
                || property.getEntity() == entity) {
            return true;
        }
        return super.isContain(entity);
    }

    @Override
    public void appendToQuery(SQLStream sql, Map model) {
        sql.append(property.getAlias());
    }

    @Override
    public Object getValue(Map constants) throws ReportException {
        return constants.get(property);
    }

    @Override
    public void buildUsedSet(UsedReportableType cls, Set set) {
        if(cls == UsedReportableType.property) {
            set.add(property);
        }
    }

}
TOP

Related Classes of reportgen.math.reference.method.MathExpressionEntityMethodRef

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.