思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c

以下内容为反编译后的 AMPExtension.java 源代码,内容仅作参考


package org.jivesoftware.smackx.amp.packet;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jivesoftware.smack.packet.ExtensionElement;
public class AMPExtension implements ExtensionElement {
    public static final String ELEMENT = "amp";
    public static final String NAMESPACE = "http://jabber.org/protocol/amp";
    public final String from;
    public boolean perHop;
    public final CopyOnWriteArrayList<Rule> rules;
    public final Status status;
    public final String to;

    public enum Action {
        alert,
        drop,
        error,
        notify;
        
        public static final String ATTRIBUTE_NAME = "action";
    }

    public interface Condition {
        public static final String ATTRIBUTE_NAME = "condition";

        String getName();

        String getValue();
    }

    public static class Rule {
        public static final String ELEMENT = "rule";
        public final Action action;
        public final Condition condition;

        public Rule(Action action, Condition condition) {
            if (action == null) {
                throw new NullPointerException("Can't create Rule with null action");
            }
            if (condition != null) {
                this.action = action;
                this.condition = condition;
                return;
            }
            throw new NullPointerException("Can't create Rule with null condition");
        }

        public String toXML() {
            return "<rule action=\"" + this.action.toString() + "\" " + Condition.ATTRIBUTE_NAME + "=\"" + this.condition.getName() + "\" value=\"" + this.condition.getValue() + "\"/>";
        }

        public Action getAction() {
            return this.action;
        }

        public Condition getCondition() {
            return this.condition;
        }
    }

    public enum Status {
        alert,
        error,
        notify
    }

    public AMPExtension(String str, String str2, Status status) {
        this.rules = new CopyOnWriteArrayList<>();
        this.perHop = false;
        this.from = str;
        this.to = str2;
        this.status = status;
    }

    public void addRule(Rule rule) {
        this.rules.add(rule);
    }

    @Override
    public String getElementName() {
        return ELEMENT;
    }

    public String getFrom() {
        return this.from;
    }

    @Override
    public String getNamespace() {
        return NAMESPACE;
    }

    public List<Rule> getRules() {
        return Collections.unmodifiableList(this.rules);
    }

    public int getRulesCount() {
        return this.rules.size();
    }

    public Status getStatus() {
        return this.status;
    }

    public String getTo() {
        return this.to;
    }

    public synchronized boolean isPerHop() {
        return this.perHop;
    }

    public synchronized void setPerHop(boolean z) {
        this.perHop = z;
    }

    @Override
    public String toXML(String str) {
        StringBuilder sb = new StringBuilder();
        sb.append('<');
        sb.append(getElementName());
        sb.append(" xmlns=\"");
        sb.append(getNamespace());
        sb.append('\"');
        if (this.status != null) {
            sb.append(" status=\"");
            sb.append(this.status.toString());
            sb.append('\"');
        }
        if (this.to != null) {
            sb.append(" to=\"");
            sb.append(this.to);
            sb.append('\"');
        }
        if (this.from != null) {
            sb.append(" from=\"");
            sb.append(this.from);
            sb.append('\"');
        }
        if (this.perHop) {
            sb.append(" per-hop=\"true\"");
        }
        sb.append('>');
        for (Rule rule : getRules()) {
            sb.append(rule.toXML());
        }
        sb.append("</");
        sb.append(getElementName());
        sb.append('>');
        return sb.toString();
    }

    public AMPExtension() {
        this.rules = new CopyOnWriteArrayList<>();
        this.perHop = false;
        this.from = null;
        this.to = null;
        this.status = null;
    }
}