001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.common.messaging;
017
018import java.util.ArrayList;
019import java.util.List;
020
021/**
022 * Response that can contain a list of related responses.
023 *
024 * @param <T> Content type of the root response
025 * @param <R> Content type of each individual related response
026 */
027public class ResponseChain<T, R> extends Response<T> {
028
029  private List<Response<R>> relatedResponses;
030
031  public ResponseChain() {
032    relatedResponses = new ArrayList<Response<R>>();
033  }
034
035  public ResponseChain(Response.Status status) {
036    super(status);
037    relatedResponses = new ArrayList<Response<R>>();
038  }
039
040  public ResponseChain(Response.Status status, String messageKey) {
041    super(status, messageKey);
042    relatedResponses = new ArrayList<Response<R>>();
043  }
044
045  public ResponseChain(Response.Status status, T content, String messageKey) {
046    super(status, content, messageKey);
047    relatedResponses = new ArrayList<Response<R>>();
048  }
049
050  /**
051   * @return the relatedResponses
052   */
053  public List<Response<R>> getRelatedResponses() {
054    return relatedResponses;
055  }
056
057  /**
058   * @param relatedResponses the relatedResponses to set
059   */
060  public void setRelatedResponses(List<Response<R>> relatedResponses) {
061    this.relatedResponses = relatedResponses;
062  }
063
064  /**
065   * Adds a response to the list of related response.
066   */
067  public void append(Response<R> response) {
068    relatedResponses.add(response);
069  }
070
071}