1 /* 2 * #%L 3 * Bitrepository Core 4 * %% 5 * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark 6 * %% 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation, either version 2.1 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Lesser Public License for more details. 16 * 17 * You should have received a copy of the GNU General Lesser Public 18 * License along with this program. If not, see 19 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 20 * #L% 21 */ 22 package org.bitrepository.service.exception; 23 24 import org.bitrepository.bitrepositoryelements.ResponseInfo; 25 26 /** 27 * The exception for the request handlers. 28 */ 29 @SuppressWarnings("serial") 30 public abstract class RequestHandlerException extends Exception { 31 /** The ResponseInfo wrapped by this exception. Tells the reason for the exception.*/ 32 private final ResponseInfo responseInfo; 33 /** The id of the collection, which this exception is relevant for, if any. */ 34 private String collectionId; 35 36 /** 37 * Constructor. 38 * @param rInfo The ResponseInfo for this class to wrap. 39 * @param collectionID The id of the collection. Use 'null' if no collection is relevant. 40 */ 41 public RequestHandlerException(ResponseInfo rInfo, String collectionId) { 42 super(rInfo.getResponseText()); 43 this.responseInfo = rInfo; 44 this.collectionId = collectionId; 45 } 46 47 /** 48 * Constructor. 49 * @param rInfo The ResponseInfo for this class to wrap. 50 * @param collectionID The id of the collection. Use 'null' if no collection is relevant. 51 * @param e The exception to wrap into the StackTrace. 52 */ 53 public RequestHandlerException(ResponseInfo rInfo, String collectionId, Exception e) { 54 super(rInfo.getResponseText(), e); 55 this.responseInfo = rInfo; 56 this.collectionId = collectionId; 57 } 58 59 /** 60 * @return The wrapped ResponseInfo. 61 */ 62 public ResponseInfo getResponseInfo() { 63 return responseInfo; 64 } 65 66 /** 67 * @return The id of the collection regarding this exception. 68 */ 69 public String getCollectionId() { 70 return collectionId; 71 } 72 73 /** 74 * @param collectionId The id of the collection. 75 */ 76 public void setCollectionId(String collectionId) { 77 this.collectionId = collectionId; 78 } 79 80 @Override 81 public String toString() { 82 return super.toString() + ", " + responseInfo.toString(); 83 } 84 }