⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formfactory.java

📁 CRMS客户关系管理系统(JAVA版),这是一个客户关系管理系统。
💻 JAVA
字号:
    /* CRMS, customer relationship management system    Copyright (C) 2003  Service To Youth Council    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 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 General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    For further information contact the SYC ICT department on GPL@syc.net.au    98 Kermode Street    North Adelaide    South Australia    SA 5006     +61 (0)8 8367 0755    *//* * FormFactory.java * * Created on 14 April 2003, 03:41 */package crms.form;import java.util.*;import java.io.*;import org.w3c.dom.*;import org.jdom.*;import org.jdom.output.*;import org.jdom.input.*;import org.apache.log4j.Logger;import java.lang.reflect.*;import crms.util.*;/** * * @author  dmurphy */public class FormFactory {        private static FormFactory _instance = null;        private HashMap formCache = new HashMap();    private File formDirectory = null;        static Logger logger = Logger.getLogger(FormFactory.class);        /** Creates a new instance of FormFactory */    private FormFactory() {    }        public void setFormDirectory(File dir) {        this.formDirectory = dir;    }        public static FormFactory getInstance() {        if (_instance == null) {            _instance = new FormFactory();        }                return _instance;    }            public Form createForm(ServerCommand command) {                String formName = (String) command.getParameterValue(ServerCommand.PARAM_FORM_NAME);                Form cached = (Form) formCache.get(formName);                File formFile = new File(formDirectory, formName + ".xml");                if (!formFile.exists()) {            throw new RuntimeException("Form file: " + formFile + " not found...");        }        // If the xml file has changed, grab it and parse it again        // otherwise return the cached one        if (cached != null && cached.getDateCreated().getTime() >formFile.lastModified()) {            logger.debug("Returning cached copy of form...");            return cached;        } else {            logger.debug("Source xml file " + formFile.toString() + " has changed, reparsing...");        }                Form theForm = null;                try {                    SAXBuilder builder = new SAXBuilder(false);            org.jdom.Document doc = builder.build(formFile);            DOMOutputter domOut = new DOMOutputter();            org.w3c.dom.Document newDoc = domOut.output(doc);            theForm = FormXML.createForm(newDoc.getDocumentElement());            theForm.setDateCreated(new Date());                        // Now that we've got the form object, see if there are any            // class specifications in any of the fields that we need to            // expand into options lists.            processOptionExpansions(theForm);                        if (theForm.getPreprocessor() != null) {                prePopulateForm(theForm, command);            }                        formCache.put(formName, theForm);        }        catch (Exception ex) {            ex.printStackTrace();            throw new RuntimeException(ex);        }        return theForm;    }        public void processOptionExpansions(Form form) {        for (int i=0; i < form.getFieldCount(); i++) {            FormField field = form.getField(i);                        if (field.getListClass() != null ) {                expandOptions(field);            }        }    }        public void expandOptions(FormField field) {        try {            Class clazz = Class.forName(field.getListClass());                        Object obj = clazz.newInstance();                        if (!ListProducer.class.isAssignableFrom(clazz)) {                throw new RuntimeException("Can only expand options for class which implements ListProducer...");            }                        Method method = clazz.getMethod("produceList",null);                        ArrayList list = (ArrayList) method.invoke(obj, null);            for (int i=0; i < list.size(); i++) {                AbstractCode code = (AbstractCode) list.get(i);                field.addOption(new FieldOption(code));            }        }        catch (Exception ex) {            ex.printStackTrace();            throw new RuntimeException(ex);        }    }        public void prePopulateForm(Form form, ServerCommand command) {        try {            Class clazz = Class.forName(form.getPreprocessor());                        FormPreProcessor proc = (FormPreProcessor) clazz.newInstance();            proc.preProcess(form,command);        }        catch (Exception ex) {            ex.printStackTrace();            throw new RuntimeException(ex);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -