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

📄 userinterface.java

📁 开源的axis2框架的源码。用于开发WEBSERVER
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        SOAPRadio = new JRadioButton("SOAP with Attachments");
        SOAPRadio.setBounds(140, 295, 200, 20);

        opLabel = new JLabel("Select Operation");
        opLabel.setBounds(20, 320, 150, 20);

        sendRadio = new JRadioButton("Send");
        sendRadio.setBounds(20, 345, 100, 20);
        sendRadio.setSelected(true);

        sendRecRadio = new JRadioButton("Send & Receive");
        sendRecRadio.setBounds(140, 345, 150, 20);

        cacheBox = new JCheckBox("Enable Client Side File Caching");
        cacheBox.setSelected(false);
        cacheBox.setEnabled(false);
        cacheBox.setBounds(20, 380, 250, 20);

        thresholdLabel = new JLabel("File Cache Threshold: ");
        thresholdLabel.setBounds(50, 410, 150, 20);
        thresholdLabel.setEnabled(false);
        cacheThresholdText = new JTextField();
        cacheThresholdText.setBounds(200, 410, 40, 20);
        cacheThresholdText.setEnabled(false);

        bytesLabel = new JLabel("(in bytes)");
        bytesLabel.setBounds(250, 410, 100, 20);
        bytesLabel.setEnabled(false);

        cacheFolderLabel = new JLabel("Cache Folder: ");
        cacheFolderLabel.setBounds(50, 440, 150, 20);
        cacheFolderLabel.setEnabled(false);
        cacheFolderText = new JTextField();
        cacheFolderText.setBounds(200, 440, 210, 20);
        cacheFolderText.setEnabled(false);

        brwsBut2 = new JButton("...");
        brwsBut2.setBounds(420, 440, 30, 20);
        brwsBut2.setToolTipText("Browse for a cache folder");
        brwsBut2.setEnabled(false);

        this.executeButton = new JButton("Execute");
        executeButton.setBounds(((WIDTH - 200) / 2), 490, 200, 20);

        fileChooser = new JFileChooser();
        fileChooser.setName("File Chooser");
    }

    public void handleSelection() {
        if (!files.isEmpty()) {
            removeButton.setEnabled(false);
        }
    }

    public void enableCaching() {
        cacheEnable = cacheBox.isSelected();
        thresholdLabel.setEnabled(cacheEnable);
        cacheThresholdText.setEnabled(cacheEnable);
        cacheFolderLabel.setEnabled(cacheEnable);
        cacheFolderText.setEnabled(cacheEnable);
        brwsBut2.setEnabled(cacheEnable);
        bytesLabel.setEnabled(cacheEnable);
    }

    public void switchRadios(JRadioButton me, JRadioButton partner) {
        me.setSelected(true);
        partner.setSelected(false);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == brwsBut1) {
            String str = browse(JFileChooser.FILES_ONLY);
            if(str != null){
                fileField.setText(str);
                addFileButton.setEnabled(true);
            }
        } else if (e.getSource() == brwsBut2) {
            String str = browse(JFileChooser.FILES_AND_DIRECTORIES);
            if(str != null){
                cacheFolderText.setText(str);
            }
        } else if (e.getSource() == executeButton) {
            execute();
        } else if (e.getSource() == addFileButton) {
            addFile();
        } else if (e.getSource() == removeButton) {
            removeFromList();
        }
    }

    public String browse(int selectionMode) {
        fileChooser.setFileSelectionMode(selectionMode);
        int returnVal = fileChooser.showDialog(this, "Select");

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fileChooser.getSelectedFile();
            if (file.getAbsolutePath() != null) {
                return file.getAbsolutePath();
            }
        }
        fileChooser.setSelectedFile(null);
        return null;
    }

    public void addFile() {
        file = new File(fileField.getText());
        if (file.exists() && file.isFile()) {
            files.add(file);
            model.addElement(file.getAbsolutePath());
            fileList.setSelectedIndex(files.size() - 1);
            removeButton.setEnabled(true);
        } else {
            JOptionPane.showMessageDialog(parent,
                    "File does not exist", "File Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    public void removeFromList() {
        String selection = (String) fileList.getSelectedValue();
        if (selection != null) {
            file = new File(selection);
            files.remove(file);
            model.remove(fileList.getSelectedIndex());
            fileList.setSelectedIndex(files.size() - 1);
            if (files.isEmpty()) {
                removeButton.setEnabled(false);
            }
        }
    }

    public void execute() {
        EPR = EPRText.getText();
        String operation;
        String sendMethod;
        String cacheFolder = null;
        int cacheThreshold = 0;
        File cache;
        destFolder = destFolderText.getText();

        if (!model.isEmpty()) {
            if (destFolder.length() != 0 && EPR.length() != 0) {
                sendMethod = (MTOMRadio.isSelected() ? "MTOM" : "SOAP");
                operation = (sendRadio.isSelected() ? "send" : "sendreceive");
                if (cacheEnable) {
                    try {
                        String temp = cacheThresholdText.getText();
                        if (temp.length() != 0) {
                            cacheThreshold = Integer.parseInt(temp);
                        } else {
                            throw new NumberFormatException();
                        }

                        cache = new File(cacheFolderText.getText());
                        if (!cache.exists()) {
                            cache.mkdirs();
                        }
                        cacheFolder = cache.getAbsolutePath();

                    } catch (NumberFormatException e) {
                        JOptionPane.showMessageDialog(parent, "Please enter an integer value",
                                "Cache Threshold Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }

                mtomTest = new MTOMClientModel();
                mtomTest.setFileList(files);
                mtomTest.setTargetEPR(EPR);

                if (operation.equals("send")) {
                    send(sendMethod);
                } else {
                    sendAndReceive(sendMethod, cacheThreshold, cacheFolder);
                }
            } else {
                JOptionPane.showMessageDialog(parent, "Destination Folder or End Point cannot be null",
                        "Data Error", JOptionPane.ERROR_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(parent, "Add at least one file",
                    "File List Empty", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void sendAndReceive(String sendMethod, int cacheThreshold, String cacheFolder) {
        OMElement result;
        try {
            mtomTest.setCacheFolder(cacheFolder);
            mtomTest.setCacheThreshold(cacheThreshold);
            String temp = (cacheEnable) ? "Enabled" : "Disabled";
            if (sendMethod.equals("MTOM")) {
                result = mtomTest.sendReceiveUsingMTOM(destFolder, cacheEnable);

                temp = "File Caching " + temp + "\n\n" + result.getText();
                JOptionPane.showMessageDialog(parent, temp,
                        "Result of Send & Receive using MTOM", JOptionPane.PLAIN_MESSAGE);
            } else {
                result = mtomTest.sendReceiveUsingSwA(destFolder, cacheEnable);

                temp = "File Caching " + temp + "\n\n" + result.getText();
                JOptionPane.showMessageDialog(parent, temp,
                        "Result of Send & Receive using SwA", JOptionPane.PLAIN_MESSAGE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void send(String sendMethod) {
        OMElement result;
        try {
            if (sendMethod.equals("MTOM")) {
                result = mtomTest.sendFilesUsingMTOM(destFolder);
                JOptionPane.showMessageDialog(parent, result.getText(),
                        "Result of Send using MTOM", JOptionPane.PLAIN_MESSAGE);
            } else {
                result = mtomTest.sendFilesUsingSwA(destFolder);
                JOptionPane.showMessageDialog(parent, result.getText(),
                        "Result of Send using SOAP with Attachments", JOptionPane.PLAIN_MESSAGE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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