Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Copyright (C) 2010---2013 星星(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.List;
 import java.util.Map;
 
 
 public class ReportDataSetBean extends AbsConfigBean
 {
     private String id;
 
     private String datasource;//此报表所使用的数据源,默认为wabacus.cfg.xml中<datasources/>标签中的default属性配置的值
     
     private String groupid;//所有通过mergetop属性合并在一起的算一个组,它们的组ID都是第一个<dataset/>的id,如果是一个独立的<dataset/>,它的组id就是它自己的id
     
     private List<XmlElementBeanlstEleValueBeans;//存放其下配置的所有<value/>子标签,只在加载时存放一次,加载完后清空
 
     private List<ReportDataSetValueBeanlstValueBeans;//本<dataset/>中配置的所有<value/>对象
     
     
     private boolean mergetop;//当前数据集查询出的数据是否简单的合并到上一个<dataset/>中,做为上一个数据集的记录,目前只有图形报表的数据集会用到此属性
     
     private String datasetstyleproperty;//配置在<dataset/>的styleproperty的样式,只对图形报表类型有效
     
     
     public ReportDataSetBean(AbsConfigBean parent)
     {
         super(parent);
         this.=((SqlBean)parent).getDatasource();
     }
     
     public String getId()
     {
         return ;
     }
 
     public void setId(String id)
     {
         this.=id;
     }
 
     public String getGroupid()
     {
         return ;
     }
 
     public void setGroupid(String groupid)
     {
         this.=groupid;
     }
 
     public boolean isMergetop()
     {
         return ;
     }
 
     public void setMergetop(boolean mergetop)
     {
         this.=mergetop;
     }
 
     {
         return ;
     }
 
     public void setLstEleValueBeans(List<XmlElementBeanlstEleValueBeans)
     {
         this.=lstEleValueBeans;
     }
    {
        return ;
    }
    public String getDatasource()
    {
        return ;
    }
    public void setDatasource(String datasource)
    {
        if(datasource!=null&&!datasource.trim().equals(""))
        {
            this.=datasource;
        }else
        {
            this.=((SqlBean)this.getParent()).getDatasource();
        }
    }
    public String getDatasetstyleproperty(ReportRequest rrequest,boolean isStaticPart)
    {
        if(isStaticPartreturn this.;
        return WabacusAssistant.getInstance().getStylepropertyWithDynPart(rrequest,this.,this.,"");
    }
    public void setDatasetstyleproperty(String datasetstyleproperty,boolean isStaticPart)
    {
        if(isStaticPart)
        {
            this.=datasetstyleproperty;
        }else
        {
            Object[] objArr=WabacusAssistant.getInstance().parseStylepropertyWithDynPart(datasetstyleproperty);
            this.=(String)objArr[0];
            this.=(List<String>)objArr[1];
        }
    }
    {
        if(this.==nullreturn null;
        if(valueid==null||valueid.trim().equals("")) valueid=.;
        return this..get(valueid);
    }
    
    public boolean isDependentDatasetValue(String valueid)
    {
        if(valueid==null||valueid.trim().equals("")) valueid=.;
        if(this.==null||this..get(valueid)==nullreturn false;
        return this..get(valueid).isDependentDataSet();
    }
    
    public boolean loadDatasetValues()
    {
        if(==null||.size()==0) return false;
        this.=new ArrayList<ReportDataSetValueBean>();
        this.=new HashMap<String,ReportDataSetValueBean>();
        ReportBean rbean=this.getReportBean();
        List<StringlstExistDatasetids=new ArrayList<String>();//存放已经处理过的<value/>的id属性
        boolean isExistNoIdValue=false;//是否已经存在没有配置id的<value/>
        String valueidTmp;
        for(XmlElementBean eleValueBeanTmp:)
        {
            if(eleValueBeanTmp==nullcontinue;
            valueidTmp=eleValueBeanTmp.attributeValue("id");
            valueidTmp=valueidTmp==null?"":valueidTmp.trim();
            if(valueidTmp.equals(""))
            {
                if(this..size()>0)
                {//已经有<value/>,说明配置了多个<value/>
                    throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的<value/>失败,当使用多个<value/>时,所有<value/>标签必须配置id属性,且不能重复");
                }
                valueidTmp=.;
                isExistNoIdValue=true;
            }else
            {
                if(isExistNoIdValue)
                {//已经存在没有配置id的<value/>
                    throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的<value/>失败,当使用多个<value/>时,所有<value/>标签必须配置id属性,且不能重复");
                }
                if(lstExistDatasetids.contains(valueidTmp))
                {
                    throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的<value/>失败,id属性为"+valueidTmp+"的<value/>存在重复");
                }
                lstExistDatasetids.add(valueidTmp);
            }
            ReportDataSetValueBean datasetValueBean=new ReportDataSetValueBean(this);
            datasetValueBean.setId(valueidTmp.trim());
            loadReportDatasetConfig(eleValueBeanTmp,datasetValueBean);
            this..add(datasetValueBean);
            this..put(datasetValueBean.getId(),datasetValueBean);
        }
        this.=null;
        return true;
    }
    
    private void loadReportDatasetConfig(XmlElementBean eleValueBean,ReportDataSetValueBean valuebean)
    {
        String sqlValue=eleValueBean.getContent();
        sqlValue=Tools.formatStringBlank(sqlValue);
        if(sqlValue==null||sqlValue.trim().equals(""))
        {
            throw new WabacusConfigLoadingException("加载报表"+this.getReportBean().getPath()+"的<sql/>下的<value/>配置失败,没有为<value/>标签配置查询数据的SQL语句或JAVA类");
        }
        sqlValue=sqlValue.trim();
        while(sqlValue.endsWith(";"))
        {
            sqlValue=sqlValue.substring(0,sqlValue.length()-1).trim();
        }
        if(Tools.isDefineKey("class",sqlValue))
        {
            Object datasetObj=null;
            try
            {
                datasetObj=..loadClassByCurrentLoader(Tools.getRealKeyByDefine("class",sqlValue)).newInstance();
            }catch(Exception e)
            {
                throw new WabacusConfigLoadingException("为报表"+this.getReportBean().getPath()+"配置的数据集类"+sqlValue+"无法实例化",e);
            }
            if(!(datasetObj instanceof IReportDataSet))
            {
                throw new WabacusConfigLoadingException("为报表"+this.getReportBean().getPath()+"配置的数据集类"+sqlValue+"没有实现"
                        +IReportDataSet.class.getName()+"接口");
            }
            valuebean.setCustomizeDatasetObj((IReportDataSet)datasetObj);
        }else
        {
            if(sqlValue.startsWith("{")&&sqlValue.endsWith("}")) sqlValue=sqlValue.substring(1,sqlValue.length()-1).trim();
            valuebean.setValue(sqlValue);
        }
        valuebean.setDatasource(eleValueBean.attributeValue("datasource"));
        valuebean.setDependParents(eleValueBean.attributeValue("depends"));
        valuebean.setDependsConditionExpression(eleValueBean.attributeValue("dependscondition"));
        String dependstype=eleValueBean.attributeValue("dependstype");
        if(dependstype!=nullvaluebean.setDependstype(dependstype.trim());
        String seperator=eleValueBean.attributeValue("seperator");
        if(seperator!=nullvaluebean.setSeperator(seperator);
    }
    
    public void afterSqlLoad()
    {
        for(ReportDataSetValueBean valuebeanTmp:this.)
        {
            valuebeanTmp.afterSqlLoad();
        }
        List<ReportDataSetValueBeanlstResults=new ArrayList<ReportDataSetValueBean>();
        List<StringlstProcessedValueIds=new ArrayList<String>();
        ReportDataSetValueBean vbeanTmp;
        while(this..size()>0)
        {
            for(int i=0;i<this..size();i++)
            {
                vbeanTmp=this..get(i);
                if(vbeanTmp.getMDependParents()==null||vbeanTmp.getMDependParents().size()==0
                        ||hasProcessedAllParentValues(vbeanTmp,lstProcessedValueIds))
                {
                    lstProcessedValueIds.add(vbeanTmp.getId());
                    lstResults.add(vbeanTmp);
                }else
                {
                    lstTmp.add(vbeanTmp);
                }
            }
            if(lstTmp.size()==this..size())
            {
                throw new WabacusConfigLoadingException("加载报表"+this.getReportBean().getPath()+"的<sql/>中的<value/>配置失败,存在循环依赖或者依赖的父数据集ID不存在的配置");
            }
            this.=lstTmp;
            lstTmp.clear();
        }
        this.=lstResults;
    }
    
    private boolean hasProcessedAllParentValues(ReportDataSetValueBean svbeanTmp,List<StringlstProcessedValueIds)
    {
        if(svbeanTmp.getMDependParents()==null||svbeanTmp.getMDependParents().size()==0) return true;
        if(lstProcessedValueIds==null||lstProcessedValueIds.size()==0) return false;
        List<StringlstParentValueids=svbeanTmp.getAllParentValueIds();
        for(String parentValueidTmp:lstParentValueids)
        {
            if(!lstProcessedValueIds.contains(parentValueidTmp)) return false;
        }
        return true;
    }
    public AbsConfigBean clone(AbsConfigBean parent)
    {
        ReportDataSetBean dsbeanNew=(ReportDataSetBean)super.clone(parent);
        if(this.!=null)
        {
            List<ReportDataSetValueBeanlstSqlValueBeansNew=new ArrayList<ReportDataSetValueBean>();
            Map<String,ReportDataSetValueBeanmValueBeansNew=new HashMap<String,ReportDataSetValueBean>();
            ReportDataSetValueBean dsvbeanTmp;
            for(ReportDataSetValueBean svbeanTmp:this.)
            {
                dsvbeanTmp=svbeanTmp.clone(dsbeanNew);
                lstSqlValueBeansNew.add(dsvbeanTmp);
                mValueBeansNew.put(dsvbeanTmp.getId(),dsvbeanTmp);
            }
            dsbeanNew.lstValueBeans=lstSqlValueBeansNew;
            dsbeanNew.mValueBeans=mValueBeansNew;
        }
        cloneExtendConfig(dsbeanNew);
        return dsbeanNew;
    }
New to GrepCode? Check out our FAQ X