Initial code drop
[bgpcep.git] / bgp / parser-api / src / main / java / org / opendaylight / protocol / bgp / parser / BGPDocumentedException.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.parser;
9
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 import org.opendaylight.protocol.framework.DocumentedException;
14
15 /**
16  * There are several errors documented in RFC4271 or in draft, that have specific meaning for the BGP. This exception is
17  * used, when any of those errors occurs.
18  */
19 public final class BGPDocumentedException extends DocumentedException {
20
21         private static final long serialVersionUID = -6212702584439430736L;
22
23         private static final Logger logger = LoggerFactory.getLogger(BGPDocumentedException.class);
24
25         private final BGPError error;
26
27         private final byte[] data;
28
29         /**
30          * Used when an error occurred that is described in rfc or draft.
31          * 
32          * @param message message bound with this exception
33          * @param error specific documented error
34          */
35         public BGPDocumentedException(final String message, final BGPError error) {
36                 this(message, error, null);
37         }
38
39         /**
40          * Used when an error occurred that is described in rfc or draft.
41          * 
42          * @param message message bound with this exception
43          * @param error specific documented error
44          * @param data data associated with the error
45          */
46         public BGPDocumentedException(final String message, final BGPError error, final byte[] data) {
47                 super(message);
48                 this.error = error;
49                 this.data = data;
50                 logger.error("Error = " + error, this);
51         }
52
53         /**
54          * Returns specific documented error.
55          * 
56          * @return documented error
57          */
58         public BGPError getError() {
59                 return this.error;
60         }
61
62         /**
63          * Returns data associated with this error.
64          * 
65          * @return byte array data
66          */
67         public byte[] getData() {
68                 return this.data;
69         }
70 }