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

📄 bsplansbean.java

📁 一款即时通讯软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return pubsubBean.subscribeToNode(myJID, pubsubJID, node, id);
    }


    /** Called when received items event - published or retracted items. */
    public void itemsEvent(Message m, PubsubEventItems items, String id) {
        System.out.println("BSPlansBean.itemsEvent");
        if (items == null || m == null) return;

        Enumeration ie = items.items();
        if (ie == null) return;

        Vector plans = new Vector();
        while (ie.hasMoreElements()) {
            PubsubItem i = (PubsubItem) ie.nextElement();
            if (!i.isItem()) continue;
            XMLData xml = i.getXML();
            if (xml == null) continue;
            if (xml instanceof Plan) {
                System.out.println("a plan item received");
                plans.add(xml);
            }
        }

        String node = items.getNode();
        if (node == null) return;
        int index = node.lastIndexOf("/plan");
        if (index == -1) return;
        String person = node.substring(0, index);
        index = person.lastIndexOf('/');
        if (index == -1) return;
        person = person.substring(index+1);
        if (person.equals(mainFrame.username + "@" + mainFrame.server))
            return;     // my own plan

        Enumeration plansEnum = plans.elements();
        while (plansEnum.hasMoreElements()) {
            Plan plan = (Plan) plansEnum.nextElement();
            System.out.println("plan item for " + person + ":");
            System.out.println(plan);
            if (showUpdates) {
                BSPlanDialog dlg = new BSPlanDialog(mainFrame, person, plan.getPlan(), true);
                dlg.show();
            }
        }
    }


    /** Called when result of items request received. */
    public void itemsReceived(InfoQuery iq, PubsubItems items, String id) {
        System.out.println("BSPlansBean.itemsReceived");
        if (id == null || !servedIDs.contains(id) ||
            !GET_OP.equals(servedIDs.getOperation(id))) return;
        if (items == null || iq == null) return;

        servedIDs.remove(id);

        Enumeration ie = items.items();
        if (ie == null) return;

        String node = items.getNode();
        String person = node.substring(0, node.lastIndexOf("/plan"));
        person = person.substring(person.lastIndexOf('/')+1);

        if (ie == null || !ie.hasMoreElements()) {
            JOptionPane.showMessageDialog(mainFrame,
                                      "There's no plan for " + person,
                                      "Plan",
                                      JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        Vector plans = new Vector();
        while (ie.hasMoreElements()) {
            PubsubItem i = (PubsubItem) ie.nextElement();
            if (!i.isItem()) continue;
            XMLData xml = i.getXML();
            if (xml == null) continue;
            if (xml instanceof Plan) {
                System.out.println("plan item received for " + person);
                plans.add(xml);
            }
        }

        Enumeration plansEnum = plans.elements();
        while (plansEnum.hasMoreElements()) {
            Plan plan = (Plan) plansEnum.nextElement();
            //System.out.println(plan);
            BSPlanDialog dlg = new BSPlanDialog(mainFrame, person, plan.getPlan(), true);
            dlg.show();
        }
    }

    public void instantNodeCreated(InfoQuery iq, String nodeName, String id)
    {
        receivedEmptyResult(iq, id);
    }

    /** Called when an error occured */
    public void error(InfoQuery iq, String id) {
        if (id == null || !servedIDs.contains(id)) return;

        String errCode = iq.getErrorCode();
        String errMsg = iq.getErrorText();

        String op = servedIDs.getOperation(id);

        servedIDs.remove(id);

        if (op == null) return;
        String operation = null;

        if (GET_OP.equals(op))
            operation = "Get plan";
        else if (PUBLISH_OP.equals(op))
            operation = "Publish plan";
        else if (RETRACT_OP.equals(op))
        {
            operation = "Delete old plan";
            // ignore error on retract, as item may not exist.
            sendItem();
            return;
        }
        else if (SUBSCRIBE_OP.equals(op))
            operation = "Subscribe to plan";
        else if (INIT1_OP.equals(op)) {
            // if conflict don't care => continue by init2
            if ("500".equals(errCode) || "409".equals(errCode)) {
                initPlan2();
                return;
            }
            operation = "Init personal node";
        }
        else if (INIT2_OP.equals(op))
            operation = "Init plan node";
        else
            return;

        JOptionPane.showMessageDialog(mainFrame,
                                      operation + " failed. Error "
                                      + errCode + ": " + errMsg + "!",
                                      "Error",
                                      JOptionPane.ERROR_MESSAGE);
    }

    /** Called when a send fails */
    public void sendFailed(InfoQuery iq, String id) {
        if (id == null || !servedIDs.contains(id)) return;

        String op = servedIDs.getOperation(id);
        servedIDs.remove(id);

        if (op == null) return;
        String operation = null;

        if (GET_OP.equals(op))
            operation = "Get plan";
        else if (PUBLISH_OP.equals(op))
            operation = "Publish plan";
        else if (RETRACT_OP.equals(op))
            operation = "Delete old plan";
        else if (SUBSCRIBE_OP.equals(op))
            operation = "Subscribe to plan";
        else if (INIT1_OP.equals(op))
            operation = "Init personal node";
        else if (INIT2_OP.equals(op))
            operation = "Init plan node";
        else
            return;

        JOptionPane.showMessageDialog(mainFrame,
                                      operation + " failed.",
                                      "Error",
                                      JOptionPane.ERROR_MESSAGE);
    }

    /** Called when empty result (possible of previous "set") received */
    public void receivedEmptyResult(InfoQuery iq, String id) {
        if (id == null || !servedIDs.contains(id)) return;

        String op = servedIDs.getOperation(id);
        servedIDs.remove(id);

        if (op == null) return;
        String operation = null;

        if (GET_OP.equals(op))
            operation = "Get plan";
        else if (PUBLISH_OP.equals(op))
            operation = "Publish plan";
        else if (RETRACT_OP.equals(op)) {
            operation = "Delete old plan";
            sendItem();
        }
        else if (SUBSCRIBE_OP.equals(op))
            operation = "Subscribe to plan";
        else if (INIT1_OP.equals(op)) {
            operation = "Init personal node";
            initPlan2();
        }
        else if (INIT2_OP.equals(op))
            operation = "Init plan node";
        else
            return;

        JOptionPane.showMessageDialog(mainFrame,
                                      operation + " was successful.",
                                      "Plan success",
                                      JOptionPane.INFORMATION_MESSAGE);
    }


    /** Called when result of subscription request received. */
    public void subscriptionResult(InfoQuery iq, PubsubEntity entity, String id) {
        if (id == null || !servedIDs.contains(id) ||
            !SUBSCRIBE_OP.equals(servedIDs.getOperation(id))) return;

        String result = entity.getAffiliation();
        JOptionPane.showMessageDialog(mainFrame,
                                      "Subscription to plan has result: " + result,
                                      "Plan subscription",
                                      JOptionPane.INFORMATION_MESSAGE);

        servedIDs.remove(id);
    }

}

⌨️ 快捷键说明

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