Java tutorial
/* * 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.system.dataset.update; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.wabacus.config.ConfigLoadManager; import com.wabacus.config.component.application.report.ReportBean; import com.wabacus.config.xml.XmlElementBean; import com.wabacus.exception.WabacusConfigLoadingException; import com.wabacus.system.component.application.report.configbean.editablereport.AbsEditableReportEditDataBean; import com.wabacus.system.component.application.report.configbean.editablereport.EditableReportDeleteDataBean; import com.wabacus.system.dataset.update.action.AbsUpdateAction; import com.wabacus.util.Tools; public class JavaUpdateActionProvider extends AbsUpdateActionProvider { private static Log log = LogFactory.getLog(JavaUpdateActionProvider.class); private String strclasses; public boolean loadConfig(XmlElementBean eleValueBean) { if (!super.loadConfig(eleValueBean)) return false; strclasses = Tools.formatStringBlank(eleValueBean.getContent()).trim(); return !Tools.isEmpty(strclasses); } public List<AbsUpdateAction> parseAllUpdateActions(String reportTypeKey) { if (Tools.isEmpty(strclasses)) return null; ReportBean rbean = this.ownerUpdateBean.getOwner().getReportBean(); List<String> lstActionscripts = Tools.parseStringToList(this.strclasses, ";", new String[] { "\"", "\"" }, false); List<AbsUpdateAction> lstResults = new ArrayList<AbsUpdateAction>(); for (String scriptTmp : lstActionscripts) { if (scriptTmp == null || scriptTmp.trim().equals("")) continue; scriptTmp = scriptTmp.trim(); String javaname = scriptTmp; String params = null; int idx1 = scriptTmp.indexOf("("); int idx2 = scriptTmp.indexOf(")"); if (idx1 > 0 && idx2 == scriptTmp.length() - 1) { javaname = scriptTmp.substring(0, idx1).trim(); params = scriptTmp.substring(idx1 + 1, idx2).trim(); } else if (idx1 >= 0 || idx2 >= 0) { throw new WabacusConfigLoadingException("" + rbean.getPath() + "??JAVA" + scriptTmp + "??"); } Object javaActionBean; try { Class c = ConfigLoadManager.currentDynClassLoader.loadClassByCurrentLoader(javaname); javaActionBean = c.getConstructor(new Class[] { AbsEditableReportEditDataBean.class }) .newInstance(this.ownerUpdateBean); } catch (Exception e) { throw new WabacusConfigLoadingException("" + rbean.getPath() + "??JAVA" + scriptTmp + "", e); } if (!(javaActionBean instanceof AbsUpdateAction)) { throw new WabacusConfigLoadingException( "" + rbean.getPath() + "??JAVA" + scriptTmp + "" + AbsUpdateAction.class.getName()); } parseParams(params, reportTypeKey, (AbsUpdateAction) javaActionBean); lstResults.add((AbsUpdateAction) javaActionBean); } return lstResults; } private void parseParams(String params, String reportTypeKey, AbsUpdateAction javaaction) { if (params == null || params.trim().equals("")) return; if (this.ownerUpdateBean.isAutoReportdata() && !(this.ownerUpdateBean instanceof EditableReportDeleteDataBean)) { List<String> lstParamsTmp = Tools.parseStringToList(params, ",", new String[] { "'", "'" }, false); for (String paramTmp : lstParamsTmp) { if (paramTmp == null || paramTmp.trim().equals("")) continue; if (!Tools.isDefineKey("@", paramTmp)) { throw new WabacusConfigLoadingException("" + this.ownerUpdateBean.getOwner().getReportBean().getPath() + "??JAVA?" + paramTmp + "??JAVA??@{column}/@{column__old}?????<param/>"); } javaaction.createParamBeanByColbean(Tools.getRealKeyByDefine("@", paramTmp), reportTypeKey, true, true); } } else { log.warn("" + this.ownerUpdateBean.getOwner().getReportBean().getPath() + "<delete/><button/>?JAVA???" + params + "??<params/>?JAVA?"); } } }