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 error The associated error. The error description, if
074         *              specified, is used to set the exception message. Must
075         *              not be {@code null}.
076         */
077        public GeneralException(final ErrorObject error) {
078
079                this(error.getDescription(), 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         */
089        public GeneralException(final String message,
090                                final ErrorObject error) {
091
092                this(message, error, null, null, null, null, null);
093        }
094
095
096        /**
097         * Creates a new general exception.
098         *
099         * @param message The exception message. May be {@code null}.
100         * @param error   The associated error, {@code null} if not specified.
101         * @param cause   The exception cause, {@code null} if not specified.
102         */
103        public GeneralException(final String message, 
104                                final ErrorObject error,
105                                final Throwable cause) {
106        
107                this(message, error, null, null, null, null, cause);
108        }
109        
110        
111        /**
112         * Creates a new general exception.
113         *
114         * @param message      The exception message. May be {@code null}.
115         * @param error        The associated error, {@code null} if not
116         *                     specified.
117         * @param clientID     The associated client identifier, {@code null} if
118         *                     not specified.
119         * @param redirectURI  The associated redirection URI, {@code null} if
120         *                     not specified.
121         * @param responseMode The optional associated response mode,
122         *                     {@code null} if not specified.
123         * @param state        The optional associated state parameter,
124         *                     {@code null} if not specified.
125         */
126        public GeneralException(final String message, 
127                                final ErrorObject error,
128                                final ClientID clientID,
129                                final URI redirectURI,
130                                final ResponseMode responseMode,
131                                final State state) {
132        
133                this(message, error, clientID, redirectURI, responseMode, state, null);
134        }
135
136
137        /**
138         * Creates a new general exception.
139         *
140         * @param message      The exception message. May be {@code null}.
141         * @param error        The associated error, {@code null} if not
142         *                     specified.
143         * @param clientID     The associated client identifier, {@code null}
144         *                     if not specified.
145         * @param redirectURI  The associated redirection URI, {@code null} if
146         *                     not specified.
147         * @param state        The optional associated state parameter,
148         *                     {@code null} if not specified.
149         * @param responseMode The optional associated response mode,
150         *                     {@code null} if not specified.
151         * @param cause        The exception cause, {@code null} if not
152         *                     specified.
153         */
154        public GeneralException(final String message, 
155                                final ErrorObject error,
156                                final ClientID clientID,
157                                final URI redirectURI,
158                                final ResponseMode responseMode,
159                                final State state,
160                                final Throwable cause) {
161        
162                super(message, cause);
163
164                this.error = error;
165                this.clientID = clientID;
166                this.redirectURI = redirectURI;
167                this.responseMode = responseMode;
168                this.state = state;
169        }
170
171
172        /**
173         * Gets the associated error.
174         *
175         * @return The error, {@code null} if not specified.
176         */
177        public ErrorObject getErrorObject() {
178
179                return error;
180        }
181
182
183        /**
184         * Gets the associated client identifier.
185         *
186         * @return The client ID, {@code null} if not specified.
187         */
188        public ClientID getClientID() {
189
190                return clientID;
191        }
192
193
194        /**
195         * Gets the associated redirection URI.
196         *
197         * @return The redirection URI, {@code null} if redirection is not to
198         *         be performed for this error.
199         */
200        public URI getRedirectionURI() {
201
202                return redirectURI;
203        }
204
205
206        /**
207         * Gets the associated response mode.
208         *
209         * @return The response mode, {@code null} if not specified.
210         */
211        public ResponseMode getResponseMode() {
212
213                return responseMode;
214        }
215
216
217        /**
218         * Gets the optional associated state parameter.
219         *
220         * @return The optional state parameter, {@code null} if not specified 
221         *         or redirection is not to be performed.
222         */
223        public State getState() {
224
225                return state;
226        }
227}