1 /* 2 * Copyright (c) 2007, Fraunhofer-Gesellschaft 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * (1) Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the disclaimer at the end. 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * (2) Neither the name of Fraunhofer nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * DISCLAIMER 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 */ 35 package org.ogf.graap.wsag.api.exceptions; 36 37 /** 38 * Base class for WSAG4J exceptions. 39 * 40 * @author Oliver Waeldrich 41 */ 42 public abstract class WSAgreementException extends Exception 43 { 44 45 /** 46 * HTTP error code for application errors. This code identifies the overall error class. The 47 * exception-specific error code identifies the concrete exception. 48 */ 49 private static final int APPLICATION_ERROR_CLASS = 500; 50 51 /** 52 * Error code for the {@link AgreementFactoryException} 53 */ 54 public static final int AGREEMENT_FACTORY_ERROR = 1001; 55 56 /** 57 * Error code for the {@link CreationConstraintsViolationException} 58 */ 59 public static final int AGREEMENT_CONSTRAINT_VALIDATION_ERROR = 1002; 60 61 /** 62 * Error code for the {@link AgreementCreationException} 63 */ 64 public static final int AGREEMENT_CREATION_ERROR = 1003; 65 66 /** 67 * Error code for the {@link NegotiationFactoryException} 68 */ 69 public static final int NEGOTIATION_INSTANTIATION_ERROR = 2001; 70 71 /** 72 * Error code for the {@link NegotiationException} 73 */ 74 public static final int NEGOTIATION_ERROR = 2101; 75 76 /** 77 * Error code for the {@link ValidationException} 78 */ 79 public static final int NEGOTIATION_VALIDATION_ERROR = 2102; 80 81 /** 82 * Error code for the {@link ResourceUnknownException} 83 */ 84 public static final int RESOURCE_UNKNOWN_ERROR = 9001; 85 86 /** 87 * Error code for the {@link ResourceUnavailableException} 88 */ 89 public static final int RESOURCE_UNAVAILABLE_ERROR = 9002; 90 91 private static final long serialVersionUID = 1L; 92 93 /** 94 * default constructor 95 */ 96 public WSAgreementException() 97 { 98 super(); 99 } 100 101 /** 102 * Constructs the exception with the given message. 103 * 104 * @param message 105 * the exception message 106 */ 107 public WSAgreementException( String message ) 108 { 109 super( message ); 110 } 111 112 /** 113 * Constructs the exception with the given message and initializes the exception cause. 114 * 115 * @param message 116 * the exception message 117 * @param cause 118 * the exception cause 119 */ 120 public WSAgreementException( String message, Throwable cause ) 121 { 122 super( message, cause ); 123 } 124 125 /** 126 * Constructs the exception and initializes the exception cause. 127 * 128 * @param cause 129 * the exception cause 130 */ 131 public WSAgreementException( Throwable cause ) 132 { 133 super( cause ); 134 } 135 136 /** 137 * Returns a unique error code for the specific Exception; 138 * 139 * @return the exception specific error code 140 */ 141 public abstract int getErrorCode(); 142 143 /** 144 * Maps an application error to an error class. This error class reflects a HTTP error code. By default 145 * this method returns 500 as error class indicating an application error. Exceptions may overwrite this 146 * method in order to provide a more appropriate error code. 147 * 148 * @return the code of the error class 149 */ 150 public int getErrorClass() 151 { 152 return APPLICATION_ERROR_CLASS; 153 } 154 }