001    package com.nimbusds.oauth2.sdk;
002    
003    
004    import java.net.URL;
005    
006    import com.nimbusds.oauth2.sdk.id.State;
007    
008    
009    /**
010     * The base class for exceptions defined in this SDK.
011     *
012     * @author Vladimir Dzhuvinov
013     */
014    public class GeneralException extends Exception {
015    
016    
017            /**
018             * The associated error, {@code null} if not specified.
019             */
020            private final ErrorObject error;
021    
022    
023            /**
024             * The redirection URI, {@code null} if not specified or redirection is
025             * not to be performed for this error. Implies a HTTP status code 302.
026             */
027            private final URL redirectURI;
028    
029    
030            /**
031             * Optional state parameter, {@code null} if not specified.
032             */
033            private final State state;
034    
035    
036            /**
037             * Creates a new general exception.
038             *
039             * @param message The exception message. May be {@code null}.
040             */
041            public GeneralException(final String message) {
042            
043                    this(message, null);
044            }
045            
046            
047            /**
048             * Creates a new general exception.
049             *
050             * @param message The exception message. May be {@code null}.
051             * @param cause   The exception cause, {@code null} if not specified.
052             */
053            public GeneralException(final String message, final Throwable cause) {
054            
055                    this(message, null, cause);
056            }
057    
058    
059            /**
060             * Creates a new general exception.
061             *
062             * @param message The exception message. May be {@code null}.
063             * @param error   The associated error, {@code null} if not specified.
064             * @param cause   The exception cause, {@code null} if not specified.
065             */
066            public GeneralException(final String message, 
067                                    final ErrorObject error,
068                                    final Throwable cause) {
069            
070                    this(message, error, null, null, cause);
071            }
072    
073    
074            /**
075             * Creates a new general exception.
076             *
077             * @param message     The exception message. May be {@code null}.
078             * @param error       The associated error, {@code null} if not 
079             *                    specified.
080             * @param redirectURI The associated redirection URI, {@code null} if
081             *                    not specified.
082             * @param state       The optional associated state parameter, 
083             *                    {@code null} if not specified.
084             * @param cause       The exception cause, {@code null} if not
085             *                    specified.
086             */
087            public GeneralException(final String message, 
088                                    final ErrorObject error,
089                                    final URL redirectURI,
090                                    final State state,
091                                    final Throwable cause) {
092            
093                    super(message, cause);
094    
095                    this.error = error;
096                    this.redirectURI = redirectURI;
097                    this.state = state;
098            }
099    
100    
101            /**
102             * Gets the associated error.
103             *
104             * @return The error, {@code null} if not specified.
105             */
106            public ErrorObject getErrorObject() {
107    
108                    return error;
109            }
110    
111    
112            /**
113             * Gets the associated redirection URI. 
114             * 
115             * <p>Important: Must be verified with the client registry before 
116             * acting upon it!
117             *
118             * @return The redirection URI, {@code null} if redirection is not to
119             *         be performed for this error.
120             */
121            public URL getRedirectURI() {
122    
123                    return redirectURI;
124            }
125    
126    
127            /**
128             * Gets the optional associated state parameter.
129             *
130             * @return The optional state parameter, {@code null} if not specified 
131             *         or redirection is not to be performed.
132             */
133            public State getState() {
134    
135                    return state;
136            }
137    }