001/**
002 *
003 * Copyright 2014 Florian Schmaus
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.smack;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.jivesoftware.smack.util.dns.HostAddress;
023
024/**
025 * Smack uses SmackExceptions for errors that are not defined by any XMPP specification.
026 * 
027 * @author Florian Schmaus
028 */
029public class SmackException extends Exception {
030
031    /**
032     * 
033     */
034    private static final long serialVersionUID = 1844674365368214457L;
035
036    /**
037     * Creates a new SmackException with the Throwable that was the root cause of the exception.
038     * 
039     * @param wrappedThrowable the root cause of the exception.
040     */
041    public SmackException(Throwable wrappedThrowable) {
042        super(wrappedThrowable);
043    }
044
045    public SmackException(String message) {
046        super(message);
047    }
048
049    public SmackException(String message, Throwable wrappedThrowable) {
050        super(message, wrappedThrowable);
051    }
052
053    protected SmackException() {
054    }
055
056    /**
057     * Exception thrown always when there was no response to an IQ request within the packet reply
058     * timeout of the used connection instance.
059     */
060    public static class NoResponseException extends SmackException {
061        /**
062         * 
063         */
064        private static final long serialVersionUID = -6523363748984543636L;
065
066        public NoResponseException() {
067        }
068    }
069
070    public static class NotLoggedInException extends SmackException {
071
072        /**
073         * 
074         */
075        private static final long serialVersionUID = 3216216839100019278L;
076
077        public NotLoggedInException() {
078        }
079    }
080
081    public static class AlreadyLoggedInException extends SmackException {
082
083        /**
084         * 
085         */
086        private static final long serialVersionUID = 5011416918049935231L;
087
088        public AlreadyLoggedInException() {
089        }
090    }
091
092    public static class NotConnectedException extends SmackException {
093
094        /**
095         * 
096         */
097        private static final long serialVersionUID = 9197980400776001173L;
098
099        public NotConnectedException() {
100        }
101    }
102
103    public static class IllegalStateChangeException extends SmackException {
104
105        /**
106         * 
107         */
108        private static final long serialVersionUID = -1766023961577168927L;
109
110        public IllegalStateChangeException() {
111        }
112    }
113
114    public static class SecurityRequiredException extends SmackException {
115
116        /**
117         * 
118         */
119        private static final long serialVersionUID = 384291845029773545L;
120
121        public SecurityRequiredException() {
122        }
123    }
124
125    /**
126     * ConnectionException is thrown if Smack is unable to connect to all hosts of a given XMPP
127     * service. The failed hosts can be retrieved with
128     * {@link ConnectionException#getFailedAddresses()}, which will have the exception causing the
129     * connection failure set and retrievable with {@link HostAddress#getException()}.
130     */
131    public static class ConnectionException extends SmackException {
132
133        /**
134         * 
135         */
136        private static final long serialVersionUID = 1686944201672697996L;
137
138        private final List<HostAddress> failedAddresses;
139
140        public ConnectionException(Throwable wrappedThrowable) {
141            super(wrappedThrowable);
142            failedAddresses = new ArrayList<HostAddress>(0);
143        }
144
145        public ConnectionException(List<HostAddress> failedAddresses) {
146            this.failedAddresses = failedAddresses;
147        }
148
149        public List<HostAddress> getFailedAddresses() {
150            return failedAddresses;
151        }
152    }
153
154    public static class FeatureNotSupportedException extends SmackException {
155
156        /**
157         * 
158         */
159        private static final long serialVersionUID = 4713404802621452016L;
160
161        private final String feature;
162        private final String jid;
163
164        public FeatureNotSupportedException(String feature) {
165            this(feature, null);
166        }
167
168        public FeatureNotSupportedException(String feature, String jid) {
169            super(feature + " not supported" + (jid == null ? "" : " by '" + jid + "'"));
170            this.jid = jid;
171            this.feature = feature;
172        }
173
174        /**
175         * Get the feature which is not supported.
176         *
177         * @return the feature which is not supported
178         */
179        public String getFeature() {
180            return feature;
181        }
182
183        /**
184         * Get JID which does not support the feature. The JID can be null in cases when there are
185         * multiple JIDs queried for this feature.
186         *
187         * @return the JID which does not support the feature, or null
188         */
189        public String getJid() {
190            return jid;
191        }
192    }
193
194    public static class ResourceBindingNotOfferedException extends SmackException {
195
196        /**
197         * 
198         */
199        private static final long serialVersionUID = 2346934138253437571L;
200
201    }
202}