001package com.nimbusds.oauth2.sdk.client;
002
003
004import com.nimbusds.oauth2.sdk.ParseException;
005import com.nimbusds.oauth2.sdk.Response;
006import com.nimbusds.oauth2.sdk.http.HTTPResponse;
007
008
009/**
010 * The base abstract for client registration responses.
011 *
012 * <p>Related specifications:
013 *
014 * <ul>
015 *     <li>OAuth 2.0 Dynamic Client Registration Protocol 
016 *         (draft-ietf-oauth-dyn-reg-18), section 3.2.
017 * </ul>
018 */
019public abstract class ClientRegistrationResponse implements Response {
020
021
022        /**
023         * Parses a client registration response from the specified HTTP 
024         * response.
025         *
026         * @param httpResponse The HTTP response. Must not be {@code null}.
027         *
028         * @return The client registration response.
029         *
030         * @throws ParseException If the HTTP response couldn't be parsed to a
031         *                        client registration response.
032         */
033        public static ClientRegistrationResponse parse(final HTTPResponse httpResponse)
034                throws ParseException {
035                
036                if (httpResponse.getStatusCode() == HTTPResponse.SC_CREATED ||
037                    httpResponse.getStatusCode() == HTTPResponse.SC_OK) {
038
039                        return ClientInformationResponse.parse(httpResponse);
040
041                } else {
042
043                        return ClientRegistrationErrorResponse.parse(httpResponse);
044                }
045        }
046}