wizardframe.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 473 行 · 第 1/2 页

JAVA
473
字号
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                wizardComponents.getCancelAction().performAction();
            }
        });
    }

    protected void handlePragress(){
        wizardComponents.getFinishButton().setEnabled(false);
        progress.setVisible(true);
        progress.aboutToDisplayPanel();
        progress.displayingPanel();
        new java.util.Timer(true).schedule(new TimerTask() {
            public void run() {
                progress.requestStop();
            }
        }, 1000);
    }

    protected void handleSuccess(){
        StringWriter writer = new StringWriter();
        JOptionPane.showMessageDialog(this ,
                "Code genaration Successful !" + writer.toString(),
                "Axis2 code generation",
                JOptionPane.INFORMATION_MESSAGE );
        wizardComponents.setCurrentIndex(CodegenFrame.PANEL_CHOOSER);
        dispose();
    }

    protected void handleError(){
        wizardComponents.getFinishButton().setEnabled(true);
        StringWriter writer = new StringWriter();
        JOptionPane.showMessageDialog(this ,
                "Code genaration failed! !" + writer.toString(),
                "Axis2 code generation",
                JOptionPane.ERROR_MESSAGE );
    }

    private void addLibsToProjectLib(String libDirectory, String outputLocation){
        String newOutputLocation = outputLocation+File.separator+"lib";
        //Create a lib directory; all ancestor directories must exist
        boolean success = (new File(newOutputLocation)).mkdir();
        if (!success) {
            // Directory creation failed
        }
        try {
            copyDirectory(new File(libDirectory),new File(newOutputLocation));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Copies all files under srcDir to dstDir.
    // If dstDir does not exist, it will be created.

    public void copyDirectory(File srcDir, File dstDir) throws IOException {
        if (srcDir.isDirectory()) {
            if (!dstDir.exists()) {
                dstDir.mkdir();
            }

            String[] children = srcDir.list();
            for (int i=0; i<children.length; i++) {
                copyDirectory(new File(srcDir, children[i]),
                        new File(dstDir, children[i]));
            }
        } else {
            copyFile(srcDir, dstDir);
        }
    }

    // Copies src file to dst file.
    // If the dst file does not exist, it is created
    private void copyFile(File src, File dst) throws IOException {
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst);

        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    }

    // Deletes all files and subdirectories under dir.
    // Returns true if all deletions were successful.
    // If a deletion fails, the method stops attempting to delete and returns false.
    private boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i=0; i<children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }

        // The directory is now empty so delete it
        return dir.delete();
    }
    protected void doFinishWSDL2Java(){
        handlePragress();
       new java.util.Timer(true).schedule(new TimerTask() {
           public void run() {
                try {
                    FirstPanel  first=(FirstPanel)wizardComponents.getWizardPanel(1);
                    SecondPanel option=(SecondPanel)wizardComponents.getWizardPanel(3);
                    WSDL2JavaOutputPanel output=(WSDL2JavaOutputPanel)wizardComponents.getWizardPanel(5);
                    boolean isServerside,isServiceXML,isGenerateServerSideInterface  = false;
                    if (option.getGenerateAll()){
                        isServerside = true;
                        isServiceXML = true;
                        isGenerateServerSideInterface = true;
                    }else{
                        isServerside = option.isServerside();
                        isServiceXML =option.isServerXML();
                        isGenerateServerSideInterface = option.getGenerateServerSideInterface();
                    }
                    codegenBean.setPackageName(option.getPackageName());
                    codegenBean.setLanguage(option.getSelectedLanguage());
                    codegenBean.setPortName(option.getPortName());
                    codegenBean.setServiceName(option.getServiceName());
                    codegenBean.setDatabindingName(option.getDatabinderName());
                    codegenBean.setAsyncOnly(option.isAsyncOnlyOn());
                    codegenBean.setSyncOnly(option.isSyncOnlyOn());
                    codegenBean.setTestCase(option.isGenerateTestCase());
                    codegenBean.setGenerateAll(option.getGenerateAll());
                    codegenBean.setServerXML(isServiceXML);
                    codegenBean.setServerSide(isServerside);
                    codegenBean.setServerSideInterface(isGenerateServerSideInterface);
                    codegenBean.setOutput(output.getOutputLocation());
                    codegenBean.setNamespace2packageList(option.getNs2PkgMapping());
                    codegenBean.setWSDLFileName(first.getWSDLFileName());
                    codegenBean.generate();                      
                     //Add the codegen libs that are coming with the plugin to the project lib that has been created
                 if (output.getAxis2PluginLibCopyCheckBoxSelection()){
                     java.net.URL resource = WizardPanel.class.getResource("/icons/icon.png");
                     String path =new File(resource.getPath()).getParentFile().getParentFile().getParentFile().getPath();
                     System.out.println(path);
                     String pluginLibLocation = path+File.separator+"lib";
                	 addLibsToProjectLib(pluginLibLocation, output.getOutputLocation());
                 }

                 //Add the libraries on the plugin lib directory to the created project lib
                 if (output.getAxisLibCopyCheckBoxSelection() && output.oktoLoadLibs()){
                	 String libDirectory = output.getAxisJarsLocation();
                	 addLibsToProjectLib(libDirectory, output.getOutputLocation());
                 }

                 //This will Create a jar file from the codegen results and add to the output
                 //locations lib directory
                 if (output.getCreateJarCheckBoxSelection()){
                     File tempClassFile=codegenBean.getTemp();
                     tempClassFile.mkdir();
                     File srcTemp=new File(tempClassFile.getPath()+File.separator+"src");
                     srcTemp.mkdir();
                     copyDirectory(new File(output.getOutputLocation()+File.separator+"src"),srcTemp);
                     //Compile the source to another directory
                	 SrcCompiler srcCompileTool = new SrcCompiler();
                	 srcCompileTool.compileSource(tempClassFile.getPath());
                     //create the jar file and add that to the lib directory
                	 String projectLib = output.getOutputLocation()+File.separator+"lib";
                	 JarFileWriter jarFileWriter = new JarFileWriter();
                	 String jarFileName = "CodegenResults.jar";
                	 if (!output.getJarFilename().equals("")){
                		 jarFileName=output.getJarFilename();
                	 }
                	 output.setJarFileName(jarFileName);
                      File tempClass = new File(tempClassFile.getPath()+File.separator+"classes");
                     jarFileWriter.writeJarFile(new File(projectLib), jarFileName, tempClass);

                	 //Delete the temp folders
                	 deleteDir(tempClassFile );

                 }
                    progress.setVisible(false);
                    handleSuccess();
                }catch (Exception e1) {
                    e1.printStackTrace();
                    progress.setVisible(false);
                    handleError();
                }
            }
        }, 5000);

    }

    protected void doFinishJava2WSDL(){
        handlePragress();
        new java.util.Timer(true).schedule(new TimerTask() {
           public void run() {
                try {
                    wsdlgenBean.generate();
                    progress.setVisible(false);
                    handleSuccess();
                } catch (Exception e1) {
                    progress.setVisible(false);
                    handleError();
                }
            }
       }, 3100);
    }
     protected void doFinishServiceArchive(){
       handlePragress();
        new java.util.Timer(true).schedule(new TimerTask() {
            public void run() {
                 try {
                    archiveBean.finsh();
                    progress.setVisible(false);
                    handleSuccess();
                } catch (Exception e1) {
                    progress.setVisible(false);
                    handleError();
                }
            }
        }, 3100);
    }
    public void setProject(Project project){
        this.project=project;
    }
    public JComponent getRootComponent() {
        return this.getRootPane();
    }
    public void showUI() {
        pack();
        this.setVisible(true);
        show();
    }

}

⌨️ 快捷键说明

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