formbean.java

来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 2,094 行 · 第 1/5 页

JAVA
2,094
字号
    
    private void readValidatorForm (ValidatorlConfigFile configFile, FormBeanForm form) {
        JtFactory factory = new JtFactory ();      
        JtMessage msg = new JtMessage (ValidatorlConfigFile.JtREAD);
        Element elem;
        DynaMapping mappings[];
        int i;
        int count;

        if (form == null || configFile == null)
            return;

        handleTrace ("readValidatorForm (name):" + form.getName(), 0);

        msg.setMsgContent(form.getName());
        elem = (Element) factory.sendMessage(configFile, msg);

        if (elem == null) {
            handleWarning ("readValidatorForm: form not found: " + 
                    form.getName());
            
            //mappings = form.getMappings();
 
            /*
            if (mappings.length == FormBeanForm.MAX_ENTRIES)
                count = FormBeanForm.MAX_ENTRIES/2;
            else
                count = mappings.length;
            */
            
            /*
            count = FormBeanForm.INITIAL_ENTRIES;
            
            for (i = 0; i < count; i++) {
                if (mappings[i] != null)
                    mappings[i].setName("");
            }
            */
            return;
        }    

        loadForm (form, elem);

    }
    
    
    
    
    private boolean deleteValidatorForm (ValidatorlConfigFile configFile, FormBeanForm form) {
        JtFactory factory = new JtFactory ();      
        //JtMessage msg = new JtMessage (ValidatorlConfigFile.JtDELETE);
        JtMessage msg = new JtMessage (JtObject.JtREAD);
        Element elem;
        
        if (form == null || configFile == null)
            return false;
        
        
        //elem = formToValidatorElement (form, JtObject.JtDELETE);
        msg.setMsgContent(form.getName());
        elem = (Element) factory.sendMessage(configFile, msg);
        
        
        if (elem == null) {
            //handleUIError ("unable to remove form: " + form.getName());
            return false;
        }    
        
        //msg.setMsgData("form-validation/formset");
        msg = new JtMessage (JtObject.JtDELETE);
        msg.setMsgContent(elem);
        factory.sendMessage(configFile, msg);
        
        if (configFile.getObjException() != null) {
            return false;
        }
                
        return true;
    }
    
    private void deleteResources (String formName) {
        JtMessage msg = new JtMessage (ResourceFile.DELETE_GROUP);
        
        if (formName == null)
            return;
        
        
        msg.setMsgContent(formName);
        factory.sendMessage(resourceFile, msg);    
        
        if (resourceFile.getObjException() != null)
            return;
        
        factory.sendMessage(resourceFile, new JtMessage (JtObject.JtSAVE));          
    }
    
    private String concatenatePath (String path, String subpath) {
        char separator = File.separatorChar;
        File file;


        if (path == null)
            return null;
        if (subpath == null)
            return path;

        file = new File (path);


        return (file.getAbsolutePath() + separator + subpath);

    }
    
    private Object createFormBean (FormBeanForm form) {
        //JDOMAdapter adapter = new JDOMAdapter ();
        JtMessage msg1 = new JtMessage (JDOMAdapter.SAVE_FILE);
        JtMessage msg2 = new JtMessage (JDOMAdapter.ADD_ELEMENT);
        JtFactory factory = new JtFactory ();
        ValidatorlConfigFile confFile = new ValidatorlConfigFile ();
        Element newElem;
        String name;
        String path;
                
        if (form == null)
            return null;
        
        name = form.getName();
        
        if (name == null)
            return null;
        
        
     
        if (findFormBean (name) != null) {
            handleUIError ("Form bean already exists");
            return null;
        }       
            

        newElem = (Element) buildFormBean (form);

        if (newElem == null) {
            handleUIError ("Unable to create the Form Bean.");
            return (null);
        }
        
        config = (WizardConfig) factory.createObject(WizardConfig.JtCLASS_NAME);
        
        if (config == null) {
            handleError ("Unable to create configuration class");
            return (null);
        }
        factory.sendMessage(config, new JtMessage (JtObject.JtINITIALIZE));

        
        jdomAdapter.setPath(config.getConfigPath());
        
        factory.sendMessage (jdomAdapter, new JtMessage (JDOMAdapter.READ_FILE));
        
        if (jdomAdapter.getObjException() != null) {
            this.setObjException(jdomAdapter.getObjException());
            return (null);
        } 
        
        path = retrieveValidatorConfPath ();
        //handleTrace ("createFormBean:" +  path);
        
        msg2.setMsgData("struts-config/form-beans");
        msg2.setMsgContent(newElem);
        newElem.detach ();
        factory.sendMessage (jdomAdapter, msg2);

        factory.sendMessage (jdomAdapter, msg1);
        
        //path = retrieveValidatorConfPath ();
        
        if (path == null)
            return null;
        
        // path to validation.xml
        
        path = concatenatePath (config.getWebAppPath(), path);
        
        if (path == null)
            return (null);
        
        confFile.setPath(path);
                
        initializeResourceFile ();  
        
        if (!createValidatorForm (confFile, form))
            return (null);
        
        // Save ResourceFile. If createValidatorForm fails
        // the resource file won't be saved to disk.
        
        factory.sendMessage(resourceFile, new JtMessage (JtObject.JtSAVE));
        
        //if (retrieveValidatorPlugin() == null)
        //    return (null);
        
        
        return (null);               

    }   

 
    private Object updateFormBean (FormBeanForm form) {
        //JDOMAdapter adapter = new JDOMAdapter ();
        JtMessage msg = new JtMessage (JDOMAdapter.GET_CHILDREN);
        JtMessage msg1 = new JtMessage (JDOMAdapter.SAVE_FILE);
        JtMessage msg2 = new JtMessage (JDOMAdapter.ADD_ELEMENT);
        JtFactory factory = new JtFactory ();
        Element elem, newElem;
        ValidatorlConfigFile confFile = new ValidatorlConfigFile (); 

        List children;
        int i;
        String tmp;
        String name;
        String path;
                
        if (form == null)
            return null;
        
        name = form.getName();
        
        if (name == null)
            return null;
        
        config = (WizardConfig) factory.createObject(WizardConfig.JtCLASS_NAME);
        
        if (config == null) {
            handleError ("Unable to create configuration class");
            return (null);
        }
        factory.sendMessage(config, new JtMessage (JtObject.JtINITIALIZE));

        
        jdomAdapter.setPath(config.getConfigPath());
        
        msg.setMsgContent("struts-config/form-beans");
        //adapter.setPath("c:/tmp/test.xml");
               
        factory.sendMessage (jdomAdapter, new JtMessage (JDOMAdapter.READ_FILE));
        
        if (jdomAdapter.getObjException() != null) {
            this.setObjException(jdomAdapter.getObjException());
            return (null);
        } 
        
        path = retrieveValidatorConfPath ();
        
        children = (List) factory.sendMessage (jdomAdapter, msg);
        if (children == null)
            return (null);
        
        
        for (i = 0; i < children.size(); i++) {
            elem = (Element) children.get(i);
            
            tmp = elem.getAttributeValue("name");
            
            if (name.equals(tmp)) {

                newElem = (Element) buildFormBean (form);
                
                if (newElem == null) {
                    //handleError ("Unable to create the Form Bean.");
                    return (null);
                }
                msg2.setMsgData("struts-config/form-beans");
                msg2.setMsgContent(newElem);
                newElem.detach ();
                factory.sendMessage (jdomAdapter, msg2);
                
                elem.getParentElement();
                elem.detach ();
                
                
                factory.sendMessage (jdomAdapter, msg1);
                //return (null);               
                
            }
        }  
        
        if (path == null)
            return null;
        
        // path to validation.xml
        
        path = concatenatePath (config.getWebAppPath(), path);
        
        
        if (path == null)
            return (null);
        
        confFile.setPath(path);
        
        initializeResourceFile (); 
        
        if (!updateValidatorForm (confFile, form, JtObject.JtUPDATE))
            return null;
        
        // Save the Resource File. If createValidatorForm fails
        // the resource file won't be saved onto disk.
        
        factory.sendMessage(resourceFile, new JtMessage (JtObject.JtSAVE));
       
        return (null);
    } 
    
 /*   
    private void updateForm (ActionMappingForm form, Element elem) {
        List children; 
        int i;
        Element elem1;
        String name;
        
        if (form == null || elem == null)
            return;
        
        children = elem.getChildren();
        
        if (children == null)
            return;
        
        for (i = 0; i < children.size(); i++) {
            elem1 = (Element) children.get(i);
            
            if ("forward".equals (elem1.getName())) {
                name = elem1.getAttributeValue("name");
                
                if ("success".equals(name)) {
                    form.setForwardSuccess(elem1.getAttributeValue("path"));
                } else 
                    if ("failure".equals(name)) {
                        form.setForwardFailure(elem1.getAttributeValue("path"));
                    }
                
            }
            
        }
        
    }
 */
 
    /*
    private void updateBean (FormBean actionMapping, Element elem) {
        List children; 
        int i;
        Element elem1;
        String name;
        
        if (actionMapping == null || elem == null)
            return;
        
        children = elem.getChildren();
        
        if (children == null)
            return;
        
        for (i = 0; i < children.size(); i++) {
            elem1 = (Element) children.get(i);
            
            if ("forward".equals (elem1.getName())) {
                name = elem1.getAttributeValue("name");
                
                if ("success".equals(name)) {
                    actionMapping.setForwardSuccess(elem1.getAttributeValue("path"));
                } else 
                    if ("failure".equals(name)) {
                        actionMapping.setForwardFailure(elem1.getAttributeValue("path"));
                    }
                
            }
            
        }
        
    }
    */
    
    private String mapToDisplayType (String type) {
        if (type == null)
            return null;
        
        if (type.equals("java.lang.Boolean")) {
            return ("boolean");                       
        } else if (type.equals("java.lang.Byte"))
            return ("byte");  
        else if (type.equals("java.lang.Double"))
            return ("double");
        else if (type.equals("java.lang.Float"))
            return ("float"); 
        else if (type.equals("java.lang.Integer"))
            return ("integer"); 
        else if (type.equals("java.lang.Long"))
            return ("long");   
        else if (type.equals("java.lang.Short"))
            return ("short");
        else if (type.equals("java.sql.Date"))
            return ("date");        
        else
            return ("String");
        
    }
    
    private void initializeResourceFile () {
        String path;
        
        if (config == null)
            return;
        
        path = retrieveResourcePath ();
        
        if (path == null)
            return;
        
        resourceFile.setPath(path);

⌨️ 快捷键说明

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