BUG-4283 experimenter msg support - registration part
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / extension / RegistrationCloser.java
1 /**
2  * Copyright (c) 2014 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.openflowplugin.openflow.md.core.extension;
9
10 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
11 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
15 import org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava;
16 import org.opendaylight.openflowplugin.extension.api.ConvertorMessageToOFJava;
17 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
18 import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
19 import org.opendaylight.openflowplugin.extension.api.path.AugmentationPath;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
23 import org.opendaylight.yangtools.concepts.ObjectRegistration;
24 import org.opendaylight.yangtools.yang.binding.DataContainer;
25
26 /**
27  * @param <KEY> converter key
28  * @param <CONVERTER> converter instance
29  */
30 public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegistration<CONVERTER> {
31
32     private ExtensionConverterManagerImpl registrator;
33     private KEY key;
34     private CONVERTER converter;
35
36     /**
37      * @param registrator the registrator to set
38      */
39     public void setRegistrator(ExtensionConverterManagerImpl registrator) {
40         this.registrator = registrator;
41     }
42     /**
43      * @param key the key to set
44      */
45     public void setKey(KEY key) {
46         this.key = key;
47     }
48     /**
49      * @param converter the converter to set
50      */
51     public void setConverter(CONVERTER converter) {
52         this.converter = converter;
53     }
54     /**
55      * @return the registrator
56      */
57     public ExtensionConverterManagerImpl getRegistrator() {
58         return registrator;
59     }
60     /**
61      * @return the key
62      */
63     public KEY getKey() {
64         return key;
65     }
66     /**
67      * @return the converter
68      */
69     public CONVERTER getConverter() {
70         return converter;
71     }
72
73     @Override
74     public CONVERTER getInstance() {
75         return getConverter();
76     }
77
78     /**
79      * standalone deregistrator
80      * @param <TO> target type of wrapped convertor
81      */
82     public static class RegistrationCloserToOFJava<TO extends DataContainer> extends
83             RegistrationCloser<ConverterExtensionKey<? extends ExtensionKey>, ConvertorToOFJava<TO>> {
84
85         @Override
86         public void close() throws Exception {
87             getRegistrator().unregister(getKey(), getConverter());
88         }
89     }
90
91     /**
92      * standalone deregistrator
93      * @param <FROM> source type of wrapped convertor
94      * @param <PATH> associated augmentation path
95      */
96     public static class RegistrationCloserFromOFJava<FROM extends DataContainer, PATH extends AugmentationPath> extends RegistrationCloser<MessageTypeKey<?>, ConvertorFromOFJava<FROM, PATH>> {
97
98         @Override
99         public void close() throws Exception {
100             getRegistrator().unregister(getKey(), getConverter());
101         }
102     }
103
104     /**
105      * standalone deregistrator
106      * @param <TO> target type of wrapped convertor
107      */
108     public static class RegistrationCloserActionToOFJava<TO extends DataContainer> extends
109             RegistrationCloser<TypeVersionKey<? extends Action>, ConvertorActionToOFJava<Action, TO>> {
110
111         @Override
112         public void close() throws Exception {
113             getRegistrator().unregister(getKey(), getConverter());
114         }
115     }
116
117     /**
118      * standalone deregistrator
119      * @param <FROM> source type of wrapped convertor
120      * @param <PATH> associated augmentation path
121      */
122     public static class RegistrationCloserActionFromOFJava<FROM extends DataContainer, PATH extends AugmentationPath> extends
123             RegistrationCloser<MessageTypeKey<?>, ConvertorActionFromOFJava<FROM, PATH>> {
124
125         @Override
126         public void close() throws Exception {
127             getRegistrator().unregister(getKey(), getConverter());
128         }
129     }
130
131     /**
132      * standalone deregistrator
133      *
134      * @param <TO> target type of wrapped convertor
135      */
136     public static class RegistrationCloserMessageToOFJava<TO extends DataContainer> extends
137             RegistrationCloser<TypeVersionKey<? extends ExperimenterMessageOfChoice>, ConvertorMessageToOFJava<ExperimenterMessageOfChoice, TO>> {
138
139         @Override
140         public void close() throws Exception {
141             getRegistrator().unregister(getKey(), getConverter());
142         }
143     }
144
145     /**
146      * standalone deregistrator
147      *
148      * @param <FROM> source type of wrapped convertor
149      * @param <PATH> associated augmentation path
150      */
151     public static class RegistrationCloserMessageFromOFJava<FROM extends DataContainer, PATH extends AugmentationPath> extends
152             RegistrationCloser<MessageTypeKey<?>, ConvertorMessageFromOFJava<FROM, PATH>> {
153
154         @Override
155         public void close() throws Exception {
156             getRegistrator().unregister(getKey(), getConverter());
157         }
158     }
159
160
161 }