Switched BGPMessage concept to yangtools.binding.Notification.
[bgpcep.git] / bgp / parser-api / src / main / java / org / opendaylight / protocol / bgp / parser / message / BGPNotificationMessage.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.message;
9
10 import java.util.Arrays;
11
12 import org.opendaylight.protocol.bgp.parser.BGPError;
13 import org.opendaylight.yangtools.yang.binding.Notification;
14
15 /**
16  * Representation of BGPNotification message.
17  * 
18  * @see <a link="http://tools.ietf.org/html/rfc4271#section-4.5">BGP Notification Message</a>
19  */
20 public final class BGPNotificationMessage implements Notification {
21
22         private final BGPError error;
23
24         private final byte[] data;
25
26         /**
27          * Creates a BGPNotification message with no data.
28          * 
29          * @param error cause
30          */
31         public BGPNotificationMessage(final BGPError error) {
32                 this(error, null);
33         }
34
35         /**
36          * Creates a BGPNotification message with error cause and data.
37          * 
38          * @param error cause
39          * @param data associated with this message
40          */
41         public BGPNotificationMessage(final BGPError error, final byte[] data) {
42                 super();
43                 this.error = error;
44                 this.data = data;
45         }
46
47         /**
48          * Returns BGPError contained in this message.
49          * 
50          * @return the error
51          */
52         public BGPError getError() {
53                 return this.error;
54         }
55
56         /**
57          * Returns possible data associated with this message.
58          * 
59          * @return the data
60          */
61         public byte[] getData() {
62                 return this.data;
63         }
64
65         @Override
66         public String toString() {
67                 final StringBuilder builder = new StringBuilder();
68                 builder.append("BGPNotificationMessage [error=");
69                 builder.append(this.error);
70                 builder.append(", data=");
71                 builder.append(Arrays.toString(this.data));
72                 builder.append("]");
73                 return builder.toString();
74         }
75 }