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