001/**
002 *
003 * Copyright 2017 Paul Schaub
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements;
018
019import org.jivesoftware.smack.util.XmlStringBuilder;
020import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo;
021
022/**
023 * Class representing possible SOCKS5 TransportInfo elements.
024 */
025public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo {
026
027    public abstract static class JingleS5BCandidateTransportInfo extends JingleS5BTransportInfo {
028        public static final String ATTR_CID = "cid";
029
030        private final String candidateId;
031
032        protected JingleS5BCandidateTransportInfo(String candidateId) {
033            this.candidateId = candidateId;
034        }
035
036        public final String getCandidateId() {
037            return candidateId;
038        }
039
040        @Override
041        public final XmlStringBuilder toXML(String enclosingNamespace) {
042            XmlStringBuilder xml = new XmlStringBuilder();
043            xml.halfOpenElement(this);
044            xml.attribute(ATTR_CID, getCandidateId());
045            xml.closeEmptyElement();
046            return xml;
047        }
048
049        @Override
050        public final boolean equals(Object other) {
051            if (!(other instanceof JingleS5BCandidateTransportInfo)) {
052                return false;
053            }
054
055            JingleS5BCandidateTransportInfo otherCandidateTransportInfo = (JingleS5BCandidateTransportInfo) other;
056            return toXML(null).equals(otherCandidateTransportInfo.toXML(null));
057        }
058
059        @Override
060        public final int hashCode() {
061            return getCandidateId().hashCode();
062        }
063    }
064
065    public static final class CandidateActivated extends JingleS5BCandidateTransportInfo {
066        public static final String ELEMENT = "candidate-activated";
067
068        public CandidateActivated(String candidateId) {
069            super(candidateId);
070        }
071
072        @Override
073        public String getElementName() {
074            return ELEMENT;
075        }
076    }
077
078    public static final class CandidateUsed extends JingleS5BCandidateTransportInfo {
079        public static final String ELEMENT = "candidate-used";
080
081        public CandidateUsed(String candidateId) {
082            super(candidateId);
083        }
084
085        @Override
086        public String getElementName() {
087            return ELEMENT;
088        }
089    }
090
091    public static final class CandidateError extends JingleS5BTransportInfo {
092        public static final CandidateError INSTANCE = new CandidateError();
093
094        public static final String ELEMENT = "candidate-error";
095
096        private CandidateError() {
097        }
098
099        @Override
100        public String getElementName() {
101            return ELEMENT;
102        }
103
104        @Override
105        public XmlStringBuilder toXML(String enclosingNamespace) {
106            XmlStringBuilder xml = new XmlStringBuilder();
107            xml.halfOpenElement(this);
108            xml.closeEmptyElement();
109            return xml;
110        }
111
112        @Override
113        public boolean equals(Object other) {
114            return other == INSTANCE;
115        }
116
117        @Override
118        public int hashCode() {
119            return toXML(null).toString().hashCode();
120        }
121    }
122
123    public static final class ProxyError extends JingleS5BTransportInfo {
124        public static final ProxyError INSTANCE = new ProxyError();
125
126        public static final String ELEMENT = "proxy-error";
127
128        private ProxyError() {
129        }
130
131        @Override
132        public String getElementName() {
133            return ELEMENT;
134        }
135
136        @Override
137        public CharSequence toXML(String enclosingNamespace) {
138            XmlStringBuilder xml = new XmlStringBuilder();
139            xml.halfOpenElement(this);
140            xml.closeEmptyElement();
141            return xml;
142        }
143
144        @Override
145        public boolean equals(Object other) {
146            return other == INSTANCE;
147        }
148
149        @Override
150        public int hashCode() {
151            return toXML(null).toString().hashCode();
152        }
153    }
154}