001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.openid.connect.sdk.federation.config;
019
020
021import com.nimbusds.oauth2.sdk.ParseException;
022import com.nimbusds.oauth2.sdk.Response;
023import com.nimbusds.oauth2.sdk.http.HTTPResponse;
024
025
026/**
027 * Federation entity configuration response.
028 *
029 * <p>Related specifications:
030 *
031 * <ul>
032 *     <li>OpenID Connect Federation 1.0, section 5.2.
033 * </ul>
034 */
035public abstract class FederationEntityConfigurationResponse implements Response {
036        
037        
038        /**
039         * Casts this response to a federation entity configuration success
040         * response.
041         *
042         * @return The federation entity configuration success response.
043         */
044        public FederationEntityConfigurationSuccessResponse toSuccessResponse() {
045                
046                return (FederationEntityConfigurationSuccessResponse) this;
047        }
048        
049        
050        /**
051         * Casts this response to a federation entity configuration error
052         * response.
053         *
054         * @return The federation entity configuration error response.
055         */
056        public FederationEntityConfigurationErrorResponse toErrorResponse() {
057                
058                return (FederationEntityConfigurationErrorResponse) this;
059        }
060        
061        
062        /**
063         * Parses a federation entity configuration response from the specified
064         * HTTP response.
065         *
066         * @param httpResponse The HTTP response. Must not be {@code null}.
067         *
068         * @return The federation entity configuration success or error
069         *         response.
070         *
071         * @throws ParseException If the HTTP response couldn't be parsed to a
072         *                        federation entity configuration response.
073         */
074        public static FederationEntityConfigurationResponse parse(final HTTPResponse httpResponse)
075                throws ParseException {
076                
077                if (httpResponse.getStatusCode() == HTTPResponse.SC_OK) {
078                        return FederationEntityConfigurationSuccessResponse.parse(httpResponse);
079                } else {
080                        return FederationEntityConfigurationErrorResponse.parse(httpResponse);
081                }
082        }
083}