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     * @version $version$ (2013-01-30)
014     */
015    public 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 redirection URI, {@code null} if not specified or redirection is
026             * not to be performed for this error. Implies a HTTP status code 302.
027             */
028            private final URL redirectURI;
029    
030    
031            /**
032             * Optional state parameter, {@code null} if not specified.
033             */
034            private final State state;
035    
036    
037            /**
038             * Creates a new general exception.
039             *
040             * @param message The exception message. May be {@code null}.
041             */
042            public GeneralException(final String message) {
043            
044                    this(message, null);
045            }
046            
047            
048            /**
049             * Creates a new general exception.
050             *
051             * @param message The exception message. May be {@code null}.
052             * @param cause   The exception cause, {@code null} if not specified.
053             */
054            public GeneralException(final String message, final Throwable cause) {
055            
056                    this(message, null, cause);
057            }
058    
059    
060            /**
061             * Creates a new general exception.
062             *
063             * @param message The exception message. May be {@code null}.
064             * @param error   The associated error, {@code null} if not specified.
065             * @param cause   The exception cause, {@code null} if not specified.
066             */
067            public GeneralException(final String message, 
068                                    final ErrorObject error,
069                                    final Throwable cause) {
070            
071                    this(message, error, null, null, cause);
072            }
073    
074    
075            /**
076             * Creates a new general exception.
077             *
078             * @param message     The exception message. May be {@code null}.
079             * @param error       The associated error, {@code null} if not 
080             *                    specified.
081             * @param redirectURI The associated redirection URI, {@code null} if
082             *                    not specified.
083             * @param state       The optional associated state parameter, 
084             *                    {@code null} if not specified.
085             * @param cause       The exception cause, {@code null} if not
086             *                    specified.
087             */
088            public GeneralException(final String message, 
089                                    final ErrorObject error,
090                                    final URL redirectURI,
091                                    final State state,
092                                    final Throwable cause) {
093            
094                    super(message, cause);
095    
096                    this.error = error;
097                    this.redirectURI = redirectURI;
098                    this.state = state;
099            }
100    
101    
102            /**
103             * Gets the associated error.
104             *
105             * @return The error, {@code null} if not specified.
106             */
107            public ErrorObject getErrorObject() {
108    
109                    return error;
110            }
111    
112    
113            /**
114             * Gets the associated redirection URI. 
115             * 
116             * <p>Important: Must be verified with the client registry before 
117             * acting upon it!
118             *
119             * @return The redirection URI, {@code null} if redirection is not to
120             *         be performed for this error.
121             */
122            public URL getRedirectURI() {
123    
124                    return redirectURI;
125            }
126    
127    
128            /**
129             * Gets the optional associated state parameter.
130             *
131             * @return The optional state parameter, {@code null} if not specified 
132             *         or redirection is not to be performed.
133             */
134            public State getState() {
135    
136                    return state;
137            }
138    }