001package com.nimbusds.oauth2.sdk;
002
003
004import java.net.URI;
005
006import com.nimbusds.oauth2.sdk.id.ClientID;
007import com.nimbusds.oauth2.sdk.id.State;
008
009
010/**
011 * The base class for checked exceptions defined in this SDK.
012 */
013public class GeneralException extends Exception {
014
015
016        /**
017         * The associated error, {@code null} if not specified.
018         */
019        private final ErrorObject error;
020
021
022        /**
023         * The associated client identifier, {@code null} if not specified.
024         */
025        private final ClientID clientID;
026
027
028        /**
029         * The redirection URI, {@code null} if not specified or redirection is
030         * not to be performed for this error. Implies a HTTP status code 302.
031         */
032        private final URI redirectURI;
033
034
035        /**
036         * Optional response mode parameter, {@code null} if not specified.
037         */
038        private final ResponseMode responseMode;
039
040
041        /**
042         * Optional state parameter, {@code null} if not specified.
043         */
044        private final State state;
045
046
047        /**
048         * Creates a new general exception.
049         *
050         * @param message The exception message. May be {@code null}.
051         */
052        public GeneralException(final String message) {
053        
054                this(message, null, null, null, null, null, null);
055        }
056        
057        
058        /**
059         * Creates a new general exception.
060         *
061         * @param message The exception message. May be {@code null}.
062         * @param cause   The exception cause, {@code null} if not specified.
063         */
064        public GeneralException(final String message, final Throwable cause) {
065        
066                this(message, null, null, null, null, null, cause);
067        }
068
069
070        /**
071         * Creates a new general exception.
072         *
073         * @param message The exception message. May be {@code null}.
074         * @param error   The associated error, {@code null} if not specified.
075         */
076        public GeneralException(final String message,
077                                final ErrorObject error) {
078
079                this(message, error, null, null, null, null, null);
080        }
081
082
083        /**
084         * Creates a new general exception.
085         *
086         * @param message The exception message. May be {@code null}.
087         * @param error   The associated error, {@code null} if not specified.
088         * @param cause   The exception cause, {@code null} if not specified.
089         */
090        public GeneralException(final String message, 
091                                final ErrorObject error,
092                                final Throwable cause) {
093        
094                this(message, error, null, null, null, null, cause);
095        }
096        
097        
098        /**
099         * Creates a new general exception.
100         *
101         * @param message      The exception message. May be {@code null}.
102         * @param error        The associated error, {@code null} if not
103         *                     specified.
104         * @param clientID     The associated client identifier, {@code null} if
105         *                     not specified.
106         * @param redirectURI  The associated redirection URI, {@code null} if
107         *                     not specified.
108         * @param responseMode The optional associated response mode,
109         *                     {@code null} if not specified.
110         * @param state        The optional associated state parameter,
111         *                     {@code null} if not specified.
112         */
113        public GeneralException(final String message, 
114                                final ErrorObject error,
115                                final ClientID clientID,
116                                final URI redirectURI,
117                                final ResponseMode responseMode,
118                                final State state) {
119        
120                this(message, error, clientID, redirectURI, responseMode, state, null);
121        }
122
123
124        /**
125         * Creates a new general exception.
126         *
127         * @param message      The exception message. May be {@code null}.
128         * @param error        The associated error, {@code null} if not
129         *                     specified.
130         * @param clientID     The associated client identifier, {@code null}
131         *                     if not specified.
132         * @param redirectURI  The associated redirection URI, {@code null} if
133         *                     not specified.
134         * @param state        The optional associated state parameter,
135         *                     {@code null} if not specified.
136         * @param responseMode The optional associated response mode,
137         *                     {@code null} if not specified.
138         * @param cause        The exception cause, {@code null} if not
139         *                     specified.
140         */
141        public GeneralException(final String message, 
142                                final ErrorObject error,
143                                final ClientID clientID,
144                                final URI redirectURI,
145                                final ResponseMode responseMode,
146                                final State state,
147                                final Throwable cause) {
148        
149                super(message, cause);
150
151                this.error = error;
152                this.clientID = clientID;
153                this.redirectURI = redirectURI;
154                this.responseMode = responseMode;
155                this.state = state;
156        }
157
158
159        /**
160         * Gets the associated error.
161         *
162         * @return The error, {@code null} if not specified.
163         */
164        public ErrorObject getErrorObject() {
165
166                return error;
167        }
168
169
170        /**
171         * Gets the associated client identifier.
172         *
173         * @return The client ID, {@code null} if not specified.
174         */
175        public ClientID getClientID() {
176
177                return clientID;
178        }
179
180
181        /**
182         * Gets the associated redirection URI.
183         *
184         * @return The redirection URI, {@code null} if redirection is not to
185         *         be performed for this error.
186         */
187        public URI getRedirectionURI() {
188
189                return redirectURI;
190        }
191
192
193        /**
194         * Gets the associated response mode.
195         *
196         * @return The response mode, {@code null} if not specified.
197         */
198        public ResponseMode getResponseMode() {
199
200                return responseMode;
201        }
202
203
204        /**
205         * Gets the optional associated state parameter.
206         *
207         * @return The optional state parameter, {@code null} if not specified 
208         *         or redirection is not to be performed.
209         */
210        public State getState() {
211
212                return state;
213        }
214}