Add method to register listener for unknown msg
[openflowjava.git] / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / extensibility / EnhancedMessageTypeKey.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. 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.openflowjava.protocol.api.extensibility;
9
10 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
11
12
13 /**
14  * More specific key for {@link SerializerRegistry}
15  * @author michal.polkorab
16  * @param <E> main type
17  * @param <F> specific type
18  */
19 public class EnhancedMessageTypeKey<E, F> extends MessageTypeKey<E> {
20
21     private final Class<F> msgType2;
22
23     /**
24      * @param msgVersion protocol version
25      * @param msgType main type
26      * @param msgType2 subtype
27      */
28     public EnhancedMessageTypeKey(short msgVersion, Class<E> msgType, Class<F> msgType2) {
29         super(msgVersion, msgType);
30         this.msgType2 = msgType2;
31     }
32
33     @Override
34     public int hashCode() {
35         final int prime = 31;
36         int result = super.hashCode();
37         result = prime * result + ((msgType2 == null) ? 0 : msgType2.hashCode());
38         return result;
39     }
40
41     @Override
42     public boolean equals(Object obj) {
43         if (this == obj) {
44             return true;
45         }
46         if (!super.equals(obj)) {
47             return false;
48         }
49         if (getClass() != obj.getClass()) {
50             return false;
51         }
52         @SuppressWarnings("rawtypes")
53         EnhancedMessageTypeKey other = (EnhancedMessageTypeKey) obj;
54         if (msgType2 == null) {
55             if (other.msgType2 != null) {
56                 return false;
57             }
58         } else if (!msgType2.getName().equals(other.msgType2.getName())) {
59             return false;
60         }
61         return true;
62     }
63
64     @Override
65     public String toString() {
66         return super.toString() + " msgType2: " + msgType2.getName();
67     }
68 }