com.wabacus.config.component.application.report.ConditionBean.java Source code

Java tutorial

Introduction

Here is the source code for com.wabacus.config.component.application.report.ConditionBean.java

Source

/* 
 * Copyright (C) 2010---2014 (wuweixing)<349446658@qq.com>
 * 
 * This file is part of Wabacus 
 * 
 * Wabacus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.wabacus.config.component.application.report;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wabacus.config.component.application.report.condition.ConditionExpressionBean;
import com.wabacus.config.component.application.report.condition.ConditionSelectItemBean;
import com.wabacus.config.component.application.report.condition.ConditionSelectorBean;
import com.wabacus.config.component.application.report.condition.ConditionValueSelectItemBean;
import com.wabacus.exception.WabacusConfigLoadingException;
import com.wabacus.exception.WabacusRuntimeException;
import com.wabacus.system.ReportRequest;
import com.wabacus.system.assistant.ReportAssistant;
import com.wabacus.system.assistant.WabacusAssistant;
import com.wabacus.system.datatype.IDataType;
import com.wabacus.system.datatype.VarcharType;
import com.wabacus.system.inputbox.AbsInputBox;
import com.wabacus.system.inputbox.CustomizedBox;
import com.wabacus.system.inputbox.IInputBoxOwnerBean;
import com.wabacus.system.inputbox.validate.ServerValidateBean;
import com.wabacus.util.Consts;
import com.wabacus.util.Tools;

public class ConditionBean extends AbsConfigBean implements IInputBoxOwnerBean {
    private static Log log = LogFactory.getLog(ConditionBean.class);

    public final static String SELECTTYPE_INNERLOGIC = "innerlogic";

    public final static String SELECTORTYPE_COLUMNS = "columns";

    public final static String SELECTORTYPE_VALUES = "values";

    public final static String LABELPOSITION_INNER = "inner";

    public final static String LABELPOSITION_LEFT = "left";//?label

    public final static String LABELPOSITION_RIGHT = "right";

    private IDataType datatypeObj;

    private AbsInputBox inputbox;

    private String name = "";

    private String label;

    private Map<String, String> mDynLableParts;

    private String labelposition = LABELPOSITION_INNER;//?label?

    private String defaultvalue = null;

    private boolean keepkeywords;

    private String logic = " and ";

    private String tip = "";

    private boolean hidden;//???

    private boolean constant;

    private boolean br;

    private int left = 3;

    private int right = 0;//???

    //    private String relatetab="";//???tab????tab?

    private String splitlike = "0";

    private String source;

    private ConditionExpressionBean conditionExpression;//??????

    private int iterator;//?????<value/><columns/>??

    private String innerlogic;//<condition/>?innerlogic??????label?<condition/>innerlogic?

    private ConditionSelectorBean cinnerlogicbean;//???????label??<innerlogic/>??

    private ConditionSelectorBean ccolumnsbean;

    private ConditionSelectorBean cvaluesbean;

    private List<String> lstChildDisplayOrder;//??????<condition/>?

    private List<String[]> lstBelongto;

    private ServerValidateBean serverValidateBean;

    private String onsetvalueMethod;

    private String ongetvalueMethod;//??

    public ConditionBean(AbsConfigBean parent) {
        super(parent);
    }

    public String getDefaultvalue() {
        return this.defaultvalue;
    }

    public void setDefaultvalue(String defaultvalue) {
        this.defaultvalue = defaultvalue;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setServerValidateBean(ServerValidateBean svbean) {
        this.serverValidateBean = svbean;
    }

    public void setLabel(String label) {
        Object[] objArr = WabacusAssistant.getInstance().parseStringWithDynPart(this.getPageBean(), label);
        this.label = (String) objArr[0];
        this.mDynLableParts = (Map<String, String>) objArr[1];
    }

    public String getLabel() {
        return this.label;
    }

    public Map<String, String> getMDynLableParts() {
        return this.mDynLableParts;
    }

    public String getLabel(ReportRequest rrequest) {
        return WabacusAssistant.getInstance().getStringValueWithDynPart(rrequest, this.label, this.mDynLableParts,
                "");
    }

    public String getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public String getName() {
        return this.name;
    }

    public String getLabelposition() {
        return labelposition;
    }

    public void setLabelposition(String labelposition) {
        this.labelposition = labelposition;
    }

    public String getLogic() {
        return this.logic;
    }

    public IDataType getDatatypeObj() {
        return datatypeObj;
    }

    public void setDatatypeObj(IDataType datatypeObj) {
        this.datatypeObj = datatypeObj;
    }

    public boolean isHidden() {
        return hidden;
    }

    public void setHidden(boolean hidden) {
        this.hidden = hidden;
    }

    public boolean isKeepkeywords() {
        return keepkeywords;
    }

    public void setKeepkeywords(boolean keepkeywords) {
        this.keepkeywords = keepkeywords;
    }

    public AbsInputBox getInputbox() {
        return inputbox;
    }

    public void setInputbox(AbsInputBox inputbox) {
        this.inputbox = inputbox;
    }

    public boolean isBr() {
        return br;
    }

    public void setBr(boolean br) {
        this.br = br;
    }

    public boolean isConstant() {
        return constant;
    }

    public void setConstant(boolean constant) {
        this.constant = constant;
    }

    public String getSplitlike() {
        return splitlike;
    }

    public void setSplitlike(String splitlike) {
        this.splitlike = splitlike;
    }

    public String getOnsetvalueMethod() {
        return onsetvalueMethod;
    }

    public void setOnsetvalueMethod(String onsetvalueMethod) {
        this.onsetvalueMethod = onsetvalueMethod;
    }

    public String getOngetvalueMethod() {
        return ongetvalueMethod;
    }

    public void setOngetvalueMethod(String ongetvalueMethod) {
        this.ongetvalueMethod = ongetvalueMethod;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        if (source != null && !source.trim().equals("")) {
            String reportpath = "";
            if (this.getReportBean() != null)
                reportpath = this.getReportBean().getPath();
            if (Tools.isDefineKey("request", source)) {
                if (Tools.getRealKeyByDefine("request", source).trim().equals("")) {
                    throw new WabacusConfigLoadingException("" + reportpath + "name" + this.name
                            + "?source?" + source
                            + "request??key");
                }
            } else if (Tools.isDefineKey("session", source)) {
                if (Tools.getRealKeyByDefine("session", source).trim().equals("")) {
                    throw new WabacusConfigLoadingException("" + reportpath + "name" + this.name
                            + "?source?" + source
                            + "session??key");
                }
            } else {
                throw new WabacusConfigLoadingException("" + reportpath + "name" + this.name
                        + "?source" + source + "?request{...}session{...}?");
            }
            this.source = source;
            this.hidden = true;
            this.constant = false;
        } else {
            this.source = null;
        }
    }

    public String getOwnerId() {
        return name;
    }

    public String getInputBoxId() {
        return this.getReportBean().getGuid() + "_wxcondition_" + name.trim();
    }

    public boolean isConditionWithInputbox() {
        if (this.isHidden() || this.isConstant())
            return false;
        if (Tools.isDefineKey("request", this.source) || Tools.isDefineKey("session", this.source))
            return false;
        return true;
    }

    public boolean isConditionValueFromUrl() {
        if (this.isConstant())
            return false;
        if (Tools.isDefineKey("request", this.source) || Tools.isDefineKey("session", this.source))
            return false;
        return true;
    }

    public boolean isConditionValueFromSession() {
        if (this.isConstant())
            return false;
        return Tools.isDefineKey("session", this.source);
    }

    public int getLeft() {
        return left;
    }

    public void setLeft(int left) {
        this.left = left;
    }

    public int getRight() {
        return right;
    }

    public void setRight(int right) {
        this.right = right;
    }

    public ConditionExpressionBean getConditionExpression() {
        return conditionExpression;
    }

    public void setConditionExpression(ConditionExpressionBean conditionExpression) {
        this.conditionExpression = conditionExpression;
    }

    public int getIterator() {
        return iterator;
    }

    public void setIterator(int iterator) {
        this.iterator = iterator;
    }

    public String getInnerlogic() {
        return innerlogic;
    }

    public void setInnerlogic(String innerlogic) {
        if (innerlogic == null || innerlogic.trim().equals("")) {
            this.innerlogic = null;
        } else {
            if (!innerlogic.toLowerCase().trim().equals("and") && !innerlogic.toLowerCase().trim().equals("or")) {
                throw new WabacusConfigLoadingException("" + this.getReportBean().getPath()
                        + "?" + this.getName() + "?innerlogicandor");
            }
            this.innerlogic = innerlogic.trim();
        }
    }

    public ConditionSelectorBean getCinnerlogicbean() {
        return cinnerlogicbean;
    }

    public void setCinnerlogicbean(ConditionSelectorBean cinnerlogicbean) {
        this.cinnerlogicbean = cinnerlogicbean;
    }

    public ConditionSelectorBean getCcolumnsbean() {
        return ccolumnsbean;
    }

    public void setCcolumnsbean(ConditionSelectorBean ccolumnsbean) {
        this.ccolumnsbean = ccolumnsbean;
    }

    public ConditionSelectorBean getCvaluesbean() {
        return cvaluesbean;
    }

    public void setCvaluesbean(ConditionSelectorBean cvaluesbean) {
        this.cvaluesbean = cvaluesbean;
    }

    public List<String> getLstChildDisplayOrder() {
        return lstChildDisplayOrder;
    }

    public void setLstChildDisplayOrder(List<String> lstChildDisplayOrder) {
        this.lstChildDisplayOrder = lstChildDisplayOrder;
    }

    public void setBelongto(String belongto) {
        if (belongto != null) {
            belongto = belongto.trim();
            if (belongto.equals("") || belongto.equals("*.*")) {
                this.lstBelongto = null;
            } else {
                this.lstBelongto = new ArrayList<String[]>();
                List<String> lstTmp = Tools.parseStringToList(belongto, ";", false);
                String[] strArr;
                for (String strTmp : lstTmp) {
                    if (strTmp.trim().equals(""))
                        continue;
                    int idx = strTmp.indexOf(".");
                    if (idx <= 0) {
                        throw new WabacusConfigLoadingException("" + this.getReportBean().getPath()
                                + "name" + this.name
                                + "??belongto.?<dataset/><value/>ID");
                    }
                    strArr = new String[] { strTmp.substring(0, idx).trim(), strTmp.substring(idx + 1).trim() };
                    if (strArr[0].equals("*"))
                        strArr[0] = null;
                    if (strArr[1].equals("*"))
                        strArr[1] = null;
                    this.lstBelongto.add(strArr);
                }
            }
        }
    }

    public boolean isBelongTo(ReportDataSetValueBean svbean) {
        if (this.lstBelongto == null || this.lstBelongto.size() == 0)
            return true;
        String datasetid = ((ReportDataSetBean) svbean.getParent()).getId();
        for (String[] belongtoArrTmp : this.lstBelongto) {
            if ((belongtoArrTmp[0] == null || datasetid.equals(belongtoArrTmp[0]))
                    && (belongtoArrTmp[1] == null || svbean.getId().equals(belongtoArrTmp[1])))
                return true;
        }
        return false;
    }

    public boolean isExistConditionExpression(boolean inherit) {
        if (this.conditionExpression != null && this.conditionExpression.getValue() != null
                && !this.conditionExpression.getValue().trim().equals(""))
            return true;
        if (!inherit)
            return false;
        if (this.cvaluesbean == null || this.cvaluesbean.isEmpty())
            return false;
        ConditionValueSelectItemBean cvbTmp = (ConditionValueSelectItemBean) this.cvaluesbean
                .getLstSelectItemBeans().get(0);
        if (cvbTmp.getConditionExpression() != null && cvbTmp.getConditionExpression().getValue() != null
                && !cvbTmp.getConditionExpression().getValue().trim().equals("")) {
            return true;
        }
        if (cvbTmp.getLstColumnsBean() == null || cvbTmp.getLstColumnsBean().size() == 0)
            return false;
        ConditionSelectItemBean ccbeanTmp = cvbTmp.getLstColumnsBean().get(0);
        if (ccbeanTmp.getConditionExpression() != null && ccbeanTmp.getConditionExpression().getValue() != null
                && !ccbeanTmp.getConditionExpression().getValue().trim().equals("")) {
            return true;
        }
        return false;
    }

    public void initConditionValueByInitUrlMethod(ReportRequest rrequest) {
        if (!this.isConditionValueFromUrl())
            return;
        if (this.conditionExpression != null) {
            rrequest.addParamToUrl(name, "rrequest{" + name + "}", false);
        } else {
            String colselectedInputboxidTmp;
            String valueselectedInputboxidTmp;
            String innerlogicSelectedInputboxidTmp;
            if (this.iterator > 1) {//???
                for (int i = 0; i < iterator; i++) {
                    if (this.ccolumnsbean != null && !this.ccolumnsbean.isEmpty()) {
                        colselectedInputboxidTmp = this.ccolumnsbean.getSelectedInputboxId(i);
                        rrequest.addParamToUrl(colselectedInputboxidTmp,
                                "rrequest{" + colselectedInputboxidTmp + "}", true);
                    }
                    if (this.cinnerlogicbean != null && !this.cinnerlogicbean.isEmpty()
                            && this.cinnerlogicbean.getLstSelectItemBeans().size() > 1) {//?<innerlogic/>?<logic/>?
                        innerlogicSelectedInputboxidTmp = this.cinnerlogicbean.getSelectedInputboxId(i);
                        rrequest.addParamToUrl(innerlogicSelectedInputboxidTmp,
                                "rrequest{" + innerlogicSelectedInputboxidTmp + "}", true);
                    }
                    valueselectedInputboxidTmp = this.cvaluesbean.getSelectedInputboxId(i);
                    rrequest.addParamToUrl(valueselectedInputboxidTmp,
                            "rrequest{" + valueselectedInputboxidTmp + "}", true);
                    rrequest.addParamToUrl(name + "_" + i, "rrequest{" + name + "_" + i + "}", false);
                }
            } else {
                if (this.ccolumnsbean != null && !this.ccolumnsbean.isEmpty()) {
                    colselectedInputboxidTmp = this.ccolumnsbean.getSelectedInputboxId(-1);
                    rrequest.addParamToUrl(colselectedInputboxidTmp, "rrequest{" + colselectedInputboxidTmp + "}",
                            true);
                }
                if (this.cvaluesbean != null && !this.cvaluesbean.isEmpty()) {
                    valueselectedInputboxidTmp = this.cvaluesbean.getSelectedInputboxId(-1);
                    rrequest.addParamToUrl(valueselectedInputboxidTmp,
                            "rrequest{" + valueselectedInputboxidTmp + "}", true);
                }
                rrequest.addParamToUrl(name, "rrequest{" + name + "}", false);
            }
        }
    }

    public void initConditionValueByInitMethod(ReportRequest rrequest, Map<String, String> mConditionValues) {
        if (!this.isConditionValueFromUrl()) {
            mConditionValues.put(this.name, getConditionValue(rrequest, -1));
        } else if (this.conditionExpression != null || this.iterator <= 1) {
            mConditionValues.put(this.name, getConditionValue(rrequest, name));
        } else {
            for (int i = 0; i < iterator; i++) {
                mConditionValues.put(name + "_" + i, getConditionValue(rrequest, name + "_" + i));
            }
        }
    }

    private String getConditionValue(ReportRequest rrequest, String conditionname) {
        String conditionvalue = rrequest.getStringAttribute(conditionname, "");
        if ((LABELPOSITION_INNER.equals(this.labelposition) && conditionvalue.equals(this.getLabel(rrequest)))
                || conditionvalue.equals("(ALL_DATA)")) {
            conditionvalue = "";
        }
        if (conditionvalue.equals("") && this.defaultvalue != null) {//????
            conditionvalue = ReportAssistant.getInstance().getColAndConditionDefaultValue(rrequest,
                    this.defaultvalue);
        }
        rrequest.getAttributes().put(conditionname, conditionvalue);
        rrequest.addParamToUrl(conditionname, conditionvalue, true);
        return conditionvalue;
    }

    public void validateConditionValue(ReportRequest rrequest, Map<String, String> mConditionValues) {
        if (this.serverValidateBean == null)
            return;
        if (!this.isConditionValueFromUrl() || this.conditionExpression != null || this.iterator <= 1) {
            this.serverValidateBean.validate(rrequest, mConditionValues.get(this.name), mConditionValues,
                    new ArrayList<String>(), null);
        } else {//???
            for (int i = 0; i < iterator; i++) {
                this.serverValidateBean.validate(rrequest, mConditionValues.get(this.name + "_" + i),
                        mConditionValues, new ArrayList<String>(), null);
            }
        }
    }

    public String getConditionValueForSP(ReportRequest rrequest) {
        if (this.isConstant())
            return conditionExpression.getValue();
        StringBuffer conditionValueBuf = new StringBuffer();
        if (this.iterator < 2) {
            conditionValueBuf.append(getRuntimeConditionExpressionForSP(rrequest, -1));
            String conditionvalue = getDynamicConditionvalueForSql(rrequest, -1);
            if (conditionValueBuf.length() > 0) {
                conditionValueBuf.append("value=").append(conditionvalue);
            } else {
                conditionValueBuf.append(conditionvalue);
            }
        } else {
            String conditionvalueTmp;
            for (int i = 0; i < this.iterator; i++) {
                conditionvalueTmp = getDynamicConditionvalueForSql(rrequest, i);
                if (conditionvalueTmp.equals(""))
                    continue;
                conditionValueBuf.append(getRuntimeConditionExpressionForSP(rrequest, i));
                String innerlogicTmp = getInnerLogicValue(rrequest, i);
                conditionValueBuf.append("innerlogic[" + i + "]=" + innerlogicTmp).append(";");
                conditionValueBuf.append("value[" + i + "]=" + conditionvalueTmp).append(";");
            }
        }
        return conditionValueBuf.toString();
    }

    private String getRuntimeConditionExpressionForSP(ReportRequest rrequest, int index) {
        StringBuffer conditionValueBuf = new StringBuffer();
        if (this.cvaluesbean != null) {
            String valueid = rrequest.getStringAttribute(this.cvaluesbean.getSelectedInputboxId(index), "");//?ID
            ConditionSelectItemBean cvbean = this.cvaluesbean.getSelectItemBeanById(valueid);
            if (cvbean == null) {
                if (valueid.equals("")) {
                    throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                            + "?" + name + "?<value/>?");
                } else {
                    throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                            + "?" + name + "?id" + valueid + "<value/>?");
                }
            }
            conditionValueBuf.append("expressionid");
            if (index >= 0)
                conditionValueBuf.append("[" + index + "]");
            conditionValueBuf.append("=").append(cvbean.getId()).append(";");
        }
        if (this.ccolumnsbean != null) {
            String columnid = rrequest.getStringAttribute(this.ccolumnsbean.getSelectedInputboxId(index), "");
            ConditionSelectItemBean ccbean = this.ccolumnsbean.getSelectItemBeanById(columnid);
            if (ccbean == null) {
                if (columnid.equals("")) {
                    throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                            + "?" + name + "?<column/>?");
                } else {
                    throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                            + "?" + name + "?id" + columnid + "<column/>?");
                }
            }
            conditionValueBuf.append("columnid");
            if (index >= 0)
                conditionValueBuf.append("[" + index + "]");
            conditionValueBuf.append("=").append(ccbean.getId()).append(";");
        }
        return conditionValueBuf.toString();
    }

    public String getConditionExpressionAndParams(ReportRequest rrequest, List<String> lstConditions,
            List<IDataType> lstConditionsTypes) {
        if (!this.isExistConditionExpression(true))
            return null;//??<condition/>??????#name#?sql?????
        if (this.isConstant())
            return conditionExpression.getValue();
        if (this.iterator < 2) {
            String conditionvalue = getDynamicConditionvalueForSql(rrequest, -1);
            if (conditionvalue.equals(""))
                return "";
            ConditionExpressionBean cexpressionbean = getConditionRuntimeExpressionBean(rrequest, -1);
            return cexpressionbean.getRuntimeConditionExpressionValue(this, conditionvalue, lstConditions,
                    lstConditionsTypes);
        } else {
            String conditionvalueTmp;
            StringBuffer andExpressionBuf = new StringBuffer();
            StringBuffer orExpressionBuf = new StringBuffer();//or??
            List<String> lstAndConditions = null;
            List<IDataType> lstAndConditionsType = null;
            new ArrayList<IDataType>();
            List<String> lstOrConditions = null;
            new ArrayList<String>();
            List<IDataType> lstOrConditionsType = null;
            if (lstConditions != null && lstConditionsTypes != null) {
                lstAndConditions = new ArrayList<String>();
                lstAndConditionsType = new ArrayList<IDataType>();
                lstOrConditions = new ArrayList<String>();
                lstOrConditionsType = new ArrayList<IDataType>();
            }
            for (int i = 0; i < this.iterator; i++) {
                conditionvalueTmp = getDynamicConditionvalueForSql(rrequest, i);
                if (conditionvalueTmp.equals(""))
                    continue;
                String innerlogicTmp = getInnerLogicValue(rrequest, i);
                ConditionExpressionBean cexpressionbean = getConditionRuntimeExpressionBean(rrequest, i);
                if (!innerlogicTmp.equalsIgnoreCase("or")) {
                    andExpressionBuf.append(cexpressionbean.getRuntimeConditionExpressionValue(this,
                            conditionvalueTmp, lstAndConditions, lstAndConditionsType));
                    andExpressionBuf.append(" and ");
                } else {
                    orExpressionBuf.append(cexpressionbean.getRuntimeConditionExpressionValue(this,
                            conditionvalueTmp, lstOrConditions, lstOrConditionsType));
                    orExpressionBuf.append(" or ");
                }
            }
            if (andExpressionBuf.toString().endsWith(" and ")) {
                andExpressionBuf.delete(andExpressionBuf.length() - " and ".length(), andExpressionBuf.length());
            }
            if (orExpressionBuf.toString().endsWith(" or ")) {
                orExpressionBuf.delete(orExpressionBuf.length() - " or ".length(), orExpressionBuf.length());
            }
            if (andExpressionBuf.length() == 0 && orExpressionBuf.length() == 0)
                return "";
            if (lstConditions != null && lstConditionsTypes != null) {
                //and
                if (lstAndConditions.size() > 0)
                    lstConditions.addAll(lstAndConditions);
                if (lstAndConditionsType.size() > 0)
                    lstConditionsTypes.addAll(lstAndConditionsType);
                if (lstOrConditions.size() > 0)
                    lstConditions.addAll(lstOrConditions);
                if (lstOrConditionsType.size() > 0)
                    lstConditionsTypes.addAll(lstOrConditionsType);
            }
            String conditionexpression = "";
            if (!andExpressionBuf.toString().trim().equals("")) {
                conditionexpression = "(" + andExpressionBuf.toString() + ")";
            }
            if (!orExpressionBuf.toString().trim().equals("")) {
                if (conditionexpression.equals("")) {
                    conditionexpression = "(" + orExpressionBuf.toString() + ")";
                } else {
                    conditionexpression = conditionexpression + " or (" + orExpressionBuf.toString() + ")";
                }
            }
            if (!conditionexpression.trim().equals(""))
                conditionexpression = "(" + conditionexpression + ")";
            return conditionexpression;
        }
    }

    private String getInnerLogicValue(ReportRequest rrequest, int iteratorindex) {
        if ((this.innerlogic == null || this.innerlogic.trim().equals(""))
                && (this.cinnerlogicbean == null || this.cinnerlogicbean.isEmpty()))
            return "and";
        if (this.innerlogic != null && !this.innerlogic.trim().equals(""))
            return this.innerlogic;//?<condition/>innerlogic
        if (this.cinnerlogicbean.getLstSelectItemBeans().size() == 1)
            return this.cinnerlogicbean.getLstSelectItemBeans().get(0).getId();//<innerlogic/>??<logic/>
        String innerlogicTmp = rrequest
                .getStringAttribute(this.cinnerlogicbean.getSelectedInputboxId(iteratorindex), "");
        if (innerlogicTmp.equals(""))
            return this.cinnerlogicbean.getLstSelectItemBeans().get(0).getId();//?
        return innerlogicTmp;
    }

    public String getDynamicConditionvalueForSql(ReportRequest rrequest, int iteratorindex) {
        String conditionvalue = getConditionValue(rrequest, iteratorindex);
        if (conditionvalue == null || conditionvalue.trim().equals(""))
            return "";
        if ((this.datatypeObj instanceof VarcharType) && !this.splitlike.equals("0")) {
            conditionvalue = ReportAssistant.getInstance().formatCondition(conditionvalue.trim(), this.splitlike);
        }
        return conditionvalue;
    }

    public String getConditionValue(ReportRequest rrequest, int iteratorindex) {
        if (this.isConstant()) {
            if (this.getConditionExpression() == null)
                return "";
            return this.getConditionExpression().getValue();
        }
        String conditionvalue;
        if (Tools.isDefineKey("request", this.source) || Tools.isDefineKey("session", this.source)) {
            conditionvalue = WabacusAssistant.getInstance().getRequestContextStringValue(rrequest, this.source, "");
            if (conditionvalue.equals("") && this.defaultvalue != null) {
                conditionvalue = ReportAssistant.getInstance().getColAndConditionDefaultValue(rrequest,
                        this.defaultvalue);
            }
        } else {
            if (this.isHidden()) {
                conditionvalue = rrequest.getStringAttribute(name, "");
            } else {//?defaultvalue???
                String conditionname = name;
                if (iteratorindex >= 0)
                    conditionname = conditionname + "_" + iteratorindex;
                conditionvalue = rrequest.getStringAttribute(conditionname, "");
            }
        }
        return conditionvalue;
    }

    private ConditionExpressionBean getConditionRuntimeExpressionBean(ReportRequest rrequest, int index) {
        if (this.conditionExpression != null)
            return conditionExpression;
        String valueid = rrequest.getStringAttribute(this.cvaluesbean.getSelectedInputboxId(index), "");
        ConditionSelectItemBean cvbean = this.cvaluesbean.getSelectItemBeanById(valueid);
        if (cvbean == null) {
            if (valueid.equals("")) {
                throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                        + "?" + name + "?<value/>?");
            } else {
                throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                        + "?" + name + "?id" + valueid + "<value/>?");
            }
        }
        if (cvbean.getConditionExpression() != null)
            return cvbean.getConditionExpression();//<value/>???
        //<value/>?<column/>
        String columnid = rrequest.getStringAttribute(this.ccolumnsbean.getSelectedInputboxId(index), "");
        ConditionSelectItemBean ccbean = ((ConditionValueSelectItemBean) cvbean).getColumnBeanById(columnid);
        if (ccbean == null) {
            if (columnid.equals("")) {
                throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                        + "?" + name + "?<column/>?");
            } else {
                throw new WabacusRuntimeException("" + this.getReportBean().getPath()
                        + "?" + name + "?id" + columnid + "<column/>?");
            }
        }
        return ccbean.getConditionExpression();
    }

    public String getDisplayString(ReportRequest rrequest, String dynstyleproperty, int iteratorindex) {
        if (!this.isConditionWithInputbox())
            return "";
        ReportBean rbean = this.getReportBean();
        if (!rrequest.checkPermission(rbean.getId(), Consts.SEARCH_PART, name, Consts.PERMISSION_TYPE_DISPLAY))
            return "";
        if (this.iterator <= 1 && iteratorindex >= 0) {
            throw new WabacusRuntimeException("" + rbean.getPath() + "?" + this.name
                    + "iterator" + this.iterator
                    + "?iteratorindex0??");
        } else if (this.iterator > 1 && (iteratorindex < 0 || iteratorindex > this.iterator)) {
            throw new WabacusRuntimeException("" + rbean.getPath() + "?" + this.name
                    + "iterator" + this.iterator
                    + "??iteratorindex?iterator?"
                    + this.iterator);
        }
        StringBuilder resultBuf = new StringBuilder();
        resultBuf.append("<font id=\"font_").append(rbean.getGuid() + "_conditions\"");
        resultBuf.append(" name=\"font_").append(rbean.getGuid() + "_conditions\"");
        resultBuf.append(" value_name=\"").append(this.name).append("\"");
        resultBuf.append(" inputboxid=\"" + this.getInputBoxId() + "\"");//???ID?<span/>?????
        resultBuf.append(" value=\"" + Tools.htmlEncode(getConditionValue(rrequest, iteratorindex)) + "\"");
        if (!(this.inputbox instanceof CustomizedBox)) {
            if (this.cinnerlogicbean != null && !this.cinnerlogicbean.isEmpty()
                    && this.cinnerlogicbean.getLstSelectItemBeans().size() > 1) {
                resultBuf.append(" innerlogicid=\"")
                        .append(this.cinnerlogicbean.getSelectedInputboxId(iteratorindex)).append("\"");
                resultBuf.append(" innerlogicinputboxtype=\"")
                        .append(cinnerlogicbean.getInputbox() == null ? "" : cinnerlogicbean.getInputbox())
                        .append("\"");//
            }
            if (iteratorindex >= 0) {
                resultBuf.append(" iteratorindex=\"").append(iteratorindex).append("\"");
            }
            if (this.ccolumnsbean != null && !this.ccolumnsbean.isEmpty()
                    && this.ccolumnsbean.getLstSelectItemBeans().size() > 1) {
                resultBuf.append(" columnid=\"").append(this.ccolumnsbean.getSelectedInputboxId(iteratorindex))
                        .append("\"");
                resultBuf.append(" columninputboxtype=\"")
                        .append(ccolumnsbean.getInputbox() == null ? "" : ccolumnsbean.getInputbox()).append("\"");
            }
            if (this.cvaluesbean != null && !this.cvaluesbean.isEmpty()
                    && this.cvaluesbean.getLstSelectItemBeans().size() > 1) {//??
                resultBuf.append(" valueid=\"").append(this.cvaluesbean.getSelectedInputboxId(iteratorindex))
                        .append("\"");
                resultBuf.append(" valueinputboxtype=\"")
                        .append(cvaluesbean.getInputbox() == null ? "" : cvaluesbean.getInputbox()).append("\"");
            }
            resultBuf.append(">");
            resultBuf.append(showConditionAllTypeBoxes(rrequest, dynstyleproperty, iteratorindex));
            resultBuf.append("</font>");
        } else {
            if (this.iterator > 1) {
                throw new WabacusRuntimeException(
                        "" + this.getReportBean().getPath() + "?" + this.name
                                + "?iterator1????");
            }
            resultBuf.append(">");
        }
        return resultBuf.toString();
    }

    private String showConditionAllTypeBoxes(ReportRequest rrequest, String dynstyleproperty, int iteratorindex) {
        StringBuilder resultBuf = new StringBuilder();
        boolean isReadonlyPermission = rrequest.checkPermission(this.getReportBean().getId(), Consts.SEARCH_PART,
                this.name, Consts.PERMISSION_TYPE_READONLY);
        for (String childtype : this.lstChildDisplayOrder) {//?????
            if (childtype.equals("values") && this.cvaluesbean != null) {
                resultBuf.append(
                        this.cvaluesbean.showSelectedInputbox(rrequest, isReadonlyPermission, iteratorindex));
            } else if (childtype.equals("columns") && this.ccolumnsbean != null) {
                resultBuf.append(
                        this.ccolumnsbean.showSelectedInputbox(rrequest, isReadonlyPermission, iteratorindex));
            } else if (childtype.equals("inputbox")) {
                resultBuf.append(
                        showConditionInputbox(rrequest, isReadonlyPermission, dynstyleproperty, iteratorindex));
            } else if (childtype.equals("innerlogic") && this.cinnerlogicbean != null
                    && !this.cinnerlogicbean.isEmpty()) {//????iterator>1?<innerlogic/>??
                if (this.cinnerlogicbean.getLstSelectItemBeans().size() == 1) {//<innerlogic/>??<logic/>?label
                    String reallabel = cinnerlogicbean.getLstSelectItemBeans().get(0).getLabel();
                    if (reallabel != null && !reallabel.trim().equals("")) {//
                        resultBuf.append(
                                WabacusAssistant.getInstance().getSpacingDisplayString(cinnerlogicbean.getLeft()));
                        reallabel = rrequest.getI18NStringValue(reallabel);
                        resultBuf.append(reallabel);
                        resultBuf.append(
                                WabacusAssistant.getInstance().getSpacingDisplayString(cinnerlogicbean.getRight()));
                    }
                } else {
                    resultBuf.append(this.cinnerlogicbean.showSelectedInputbox(rrequest, isReadonlyPermission,
                            iteratorindex));
                }
            }
        }
        return resultBuf.toString();
    }

    private String showConditionInputbox(ReportRequest rrequest, boolean isReadonlyPermission,
            String dynstyleproperty, int iteratorindex) {
        StringBuilder resultBuf = new StringBuilder();
        String reallabel = getLabel(rrequest);
        String conditionname = this.name;
        if (iteratorindex >= 0) {
            conditionname = conditionname + "_" + iteratorindex;
        }
        String conditionvalue = rrequest.getStringAttribute(conditionname, "");
        conditionvalue = conditionvalue == null ? "" : conditionvalue.trim();
        if (reallabel != null && !reallabel.trim().equals("")) {
            if (LABELPOSITION_LEFT.equals(this.labelposition)) {//
                resultBuf.append("<span class=\"cls-search-label\">" + reallabel + "</span> ");
            } else if (LABELPOSITION_INNER.equals(this.labelposition) && conditionvalue.equals("")) {
                conditionvalue = reallabel;
            }
        }
        if (iteratorindex >= 0)
            rrequest.getAttributes().put("DYN_INPUTBOX_ID", this.getInputBoxId() + "__" + iteratorindex);
        resultBuf.append(this.inputbox.getDisplayStringValue(rrequest, conditionvalue, dynstyleproperty,
                isReadonlyPermission));
        if (reallabel != null && !reallabel.trim().equals("")
                && this.LABELPOSITION_RIGHT.equals(this.labelposition)) {
            resultBuf.append("<span class=\"cls-search-label\">" + reallabel + "</span> ");
        }
        if (iteratorindex >= 0)
            rrequest.getAttributes().remove("DYN_INPUTBOX_ID");
        return resultBuf.toString();
    }

    public void doPostLoad() {
        SqlBean sbean = (SqlBean) this.getParent();
        validateConfig(sbean);
        processInnerlogic();
        if (sbean.isSelectPreparedStatement())
            processConditionExpression();
        //        {
        //                {//???preparedstatement??????????
        //                    break;
        if (this.isConditionWithInputbox() && this.iterator > 1) {
            if (this.conditionExpression != null) {
                throw new WabacusConfigLoadingException("" + this.getReportBean().getPath()
                        + "name" + this.name
                        + "??????iterator?1");
            }
        }
        this.ongetvalueMethod = parseOnGetSetValueMethod(this.ongetvalueMethod);
        this.onsetvalueMethod = parseOnGetSetValueMethod(this.onsetvalueMethod);
        //        if(this.lstBelongto!=null&&this.lstBelongto.size()>0)
        //                if(sbean.getDatasetBeanById(belongtoIdTmp.trim())==null)
        //                            +"??belongto<value/>id"+belongtoIdTmp);
        //        }
        if (this.inputbox != null)
            this.inputbox.doPostLoad();
    }

    private String parseOnGetSetValueMethod(String method) {
        if (Tools.isEmpty(method))
            return null;
        List<String> lstMethods = Tools.parseStringToList(method, ";", false);
        StringBuilder bufTmp = new StringBuilder();
        for (String methodTmp : lstMethods) {
            bufTmp.append("{method:" + methodTmp + "},");
        }
        method = bufTmp.toString();
        if (method.endsWith(","))
            method = method.substring(0, method.length() - 1);
        if (!method.trim().equals(""))
            method = "[" + method + "]";
        return method;
    }

    private void processConditionExpression() {
        if (this.conditionExpression == null && this.cvaluesbean == null)
            return;
        if (this.conditionExpression != null && this.conditionExpression.getValue() != null
                && !this.conditionExpression.getValue().trim().equals("")) {//<conditon/><value/>????
            conditionExpression.parseConditionExpression();
        } else {
            conditionExpression = null;
            List<ConditionSelectItemBean> lstValueBeans = cvaluesbean.getLstSelectItemBeans();
            for (ConditionSelectItemBean cvbTmp : lstValueBeans) {
                if (cvbTmp.getConditionExpression() != null && cvbTmp.getConditionExpression().getValue() != null
                        && !cvbTmp.getConditionExpression().getValue().trim().equals("")) {//<values/><value/>???
                    cvbTmp.getConditionExpression().parseConditionExpression();
                } else {//<values/><value/><column/>???
                    cvbTmp.setConditionExpression(null);
                    List<ConditionSelectItemBean> lstCcbeans = ((ConditionValueSelectItemBean) cvbTmp)
                            .getLstColumnsBean();
                    for (ConditionSelectItemBean ccbeanTmp : lstCcbeans) {
                        if (ccbeanTmp.getConditionExpression() == null
                                || ccbeanTmp.getConditionExpression().getValue() == null
                                || ccbeanTmp.getConditionExpression().getValue().trim().equals("")) {
                            throw new WabacusConfigLoadingException(
                                    "" + this.getReportBean().getPath() + "name" + this.name
                                            + "????");
                        }
                        ccbeanTmp.getConditionExpression().parseConditionExpression();
                    }
                }
            }
        }
    }

    private void validateConfig(SqlBean sbean) {
        if (this.ccolumnsbean != null && this.ccolumnsbean.isEmpty())
            this.ccolumnsbean = null;
        if (this.cvaluesbean != null && this.cvaluesbean.isEmpty())
            this.cvaluesbean = null;
        if (!isConditionWithInputbox()) {
            if (this.ccolumnsbean != null || this.cvaluesbean != null) {
                throw new WabacusConfigLoadingException("" + this.getReportBean().getPath()
                        + "name" + this.name
                        + "???????<values/><columns/>");
            }
            if (this.iterator > 1) {
                throw new WabacusConfigLoadingException("" + this.getReportBean().getPath()
                        + "name" + this.name
                        + "??????<condition/>iterator?1");
            }
            if (this.innerlogic != null && !this.innerlogic.trim().equals("")
                    || this.cinnerlogicbean != null && !this.cinnerlogicbean.isEmpty()) {
                log.warn("" + this.getReportBean().getPath() + "name" + this.name
                        + "???innerlogic<innerlogic/>??");
                this.innerlogic = null;
                this.cinnerlogicbean = null;
            }
        } else {
            /*if(!sbean.isStoreProcedure())
            {
            if(this.ccolumnsbean!=null&&this.cvaluesbean==null)
            {//?<columns/><value/>???
                throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                        +"?<columns/>?<column/><value/>???");
            }
            if(this.iterator>1&&this.cvaluesbean==null)
            {
                throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                        +"???????iterator?1");
            }
            }*/
            if (cvaluesbean != null) {
                List<ConditionSelectItemBean> lstValueBeans = cvaluesbean.getLstSelectItemBeans();
                if (lstValueBeans.size() == 1 && lstValueBeans.get(0).getConditionExpression() != null) {//?<values/>?<value/><value/>???<condition/>?<value/>
                    this.cvaluesbean = null;
                    this.conditionExpression = lstValueBeans.get(0).getConditionExpression();
                    /*if(this.ccolumnsbean!=null&&!sbean.isStoreProcedure())
                    {
                    throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                            +"?<columns/>?<column/><value/>???");
                    }*/
                    return;
                }
                /*int valuecolumncnt=-1;
                ConditionValueSelectItemBean cvsibeanTmp;
                for(ConditionSelectItemBean csibeanTmp:lstValueBeans)
                {//???<value/>
                cvsibeanTmp=(ConditionValueSelectItemBean)csibeanTmp;
                if(cvsibeanTmp.getConditionExpression()!=null&&cvsibeanTmp.getLstColumnsBean()!=null&&cvsibeanTmp.getLstColumnsBean().size()>0)
                {
                    throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                            +"??<values/><value/>???<column/>????");
                }
                if(cvsibeanTmp.getConditionExpression()!=null||sbean.isStoreProcedure())
                {//<value/>????
                    if(valuecolumncnt>0)
                    {//?<value/>?<column/>
                        if(sbean.isStoreProcedure())
                        {
                            throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                                    +"???<value/>?<conlumn/>?");
                        }else
                        {
                            throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                                    +"?<values/><value/>?????<conlumn/>?");
                        }
                    }
                    valuecolumncnt=0;
                }else
                {
                    if(valuecolumncnt==0)
                    {
                        throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                                +"?<values/><value/>?????<conlumn/>?");
                    }else if(valuecolumncnt>0&&valuecolumncnt!=cvsibeanTmp.getLstColumnsBean().size())
                    {
                        throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                                +"?<values/><value/>??<conlumn/>??");
                    }
                    valuecolumncnt=cvsibeanTmp.getLstColumnsBean().size();
                    if(valuecolumncnt<2)
                    {
                        throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                                +"??<value/>??<column/>???<value/>???");
                    }
                    for(ConditionSelectItemBean ccbeanTmp:cvsibeanTmp.getLstColumnsBean())
                    {
                        if(this.ccolumnsbean==null||this.ccolumnsbean.getSelectItemBeanById(ccbeanTmp.getId())==null)
                        {//?<columns/>?id<column/>
                            throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()
                                    +"<condition/><values/>?<value/><column/>??refid"+ccbeanTmp.getId()+"<columns/>?");
                        }
                    }
                }
                }
                if(!sbean.isStoreProcedure())
                {
                if(valuecolumncnt>0&&(this.ccolumnsbean==null||this.ccolumnsbean.getLstSelectItemBeans().size()!=valuecolumncnt))
                {
                    throw new WabacusConfigLoadingException(""+this.getReportBean().getPath()+"name"+this.name
                            +"?<values/><value/>??<conlumn/>?<columns/>?<column/>??");
                }else if(valuecolumncnt==0&&this.ccolumnsbean!=null)
                {//<value/>????<column/>?<columns/>
                    log.warn(""+this.getReportBean().getPath()+"?<condition/>?<columns/>?<values/>");
                    this.ccolumnsbean=null;
                }
                }*/
            }
        }
    }

    private void processInnerlogic() {
        if (this.cinnerlogicbean != null && !this.cinnerlogicbean.isEmpty()) {//<innerlogic/>???
            String idTmp;
            for (ConditionSelectItemBean csibeanTmp : this.cinnerlogicbean.getLstSelectItemBeans()) {
                idTmp = csibeanTmp.getId().toLowerCase().trim();
                if (!idTmp.equals("and") && !idTmp.equals("or")) {
                    throw new WabacusConfigLoadingException("" + this.getReportBean().getPath()
                            + "name" + this.name
                            + "??<innerlogic/><logic/>idandor");
                }
            }
        }
        if (this.iterator < 2 && cinnerlogicbean != null && !cinnerlogicbean.isEmpty()
                && cinnerlogicbean.getLstSelectItemBeans().size() > 1) {
            throw new WabacusConfigLoadingException("" + this.getReportBean().getPath()
                    + "name" + this.name
                    + "??iterator??2?<innerlogic/>?<logic/>?");
        }
    }

    public AbsConfigBean clone(AbsConfigBean parent) {
        ConditionBean cbNew = (ConditionBean) super.clone(parent);
        if (inputbox != null) {
            cbNew.setInputbox((AbsInputBox) inputbox.clone(cbNew));
        }
        if (cinnerlogicbean != null) {
            cbNew.setCinnerlogicbean(cinnerlogicbean.clone(cbNew));
        }
        if (ccolumnsbean != null) {
            cbNew.setCcolumnsbean(ccolumnsbean.clone(cbNew));
        }
        if (cvaluesbean != null) {
            cbNew.setCvaluesbean(cvaluesbean.clone(cbNew));
        }
        if (conditionExpression != null) {
            cbNew.setConditionExpression(conditionExpression.clone());
        }
        if (lstChildDisplayOrder != null) {
            cbNew.setLstChildDisplayOrder((List<String>) ((ArrayList<String>) lstChildDisplayOrder).clone());
        }
        cloneExtendConfig(cbNew);
        return cbNew;
    }
}