Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.bgpio.exceptions; |
| 18 | |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | |
| 21 | /** |
| 22 | * Custom Exception for BGP IO. |
| 23 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame^] | 24 | public class BgpParseException extends Exception { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 25 | |
| 26 | private static final long serialVersionUID = 1L; |
| 27 | private byte errorCode; |
| 28 | private byte errorSubCode; |
| 29 | private ChannelBuffer data; |
| 30 | |
| 31 | /** |
| 32 | * Default constructor to create a new exception. |
| 33 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame^] | 34 | public BgpParseException() { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 35 | super(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Constructor to create exception from message and cause. |
| 40 | * |
| 41 | * @param message the detail of exception in string |
| 42 | * @param cause underlying cause of the error |
| 43 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame^] | 44 | public BgpParseException(final String message, final Throwable cause) { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 45 | super(message, cause); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Constructor to create exception from message. |
| 50 | * |
| 51 | * @param message the detail of exception in string |
| 52 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame^] | 53 | public BgpParseException(final String message) { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 54 | super(message); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Constructor to create exception from cause. |
| 59 | * |
| 60 | * @param cause underlying cause of the error |
| 61 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame^] | 62 | public BgpParseException(final Throwable cause) { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 63 | super(cause); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Constructor to create exception from error code and error subcode. |
| 68 | * |
| 69 | * @param errorCode error code of BGP message |
| 70 | * @param errorSubCode error subcode of BGP message |
| 71 | * @param data error data of BGP message |
| 72 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame^] | 73 | public BgpParseException(final byte errorCode, final byte errorSubCode, final ChannelBuffer data) { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 74 | super(); |
| 75 | this.errorCode = errorCode; |
| 76 | this.errorSubCode = errorSubCode; |
| 77 | this.data = data; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns errorcode for this exception. |
| 82 | * |
| 83 | * @return errorcode for this exception |
| 84 | */ |
| 85 | public byte getErrorCode() { |
| 86 | return this.errorCode; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns error Subcode for this exception. |
| 91 | * |
| 92 | * @return error Subcode for this exception |
| 93 | */ |
| 94 | public byte getErrorSubCode() { |
| 95 | return this.errorSubCode; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns error data for this exception. |
| 100 | * |
| 101 | * @return error data for this exception |
| 102 | */ |
| 103 | public ChannelBuffer getData() { |
| 104 | return this.data; |
| 105 | } |
| 106 | } |