11a7b6fed2c89081399bf43b150f2d3f19c1c70b
[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.ConvertorToOFJava;
16 import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
17 import org.opendaylight.openflowplugin.extension.api.path.AugmentationPath;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
20 import org.opendaylight.yangtools.concepts.ObjectRegistration;
21 import org.opendaylight.yangtools.yang.binding.DataContainer;
22
23 /**
24  * @param <KEY> converter key
25  * @param <CONVERTER> converter instance
26  */
27 public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegistration<CONVERTER> {
28     
29     private ExtensionConverterManagerImpl registrator;
30     private KEY key;
31     private CONVERTER converter;
32     
33     /**
34      * @param registrator the registrator to set
35      */
36     public void setRegistrator(ExtensionConverterManagerImpl registrator) {
37         this.registrator = registrator;
38     }
39     /**
40      * @param key the key to set
41      */
42     public void setKey(KEY key) {
43         this.key = key;
44     }
45     /**
46      * @param converter the converter to set
47      */
48     public void setConverter(CONVERTER converter) {
49         this.converter = converter;
50     }
51     /**
52      * @return the registrator
53      */
54     public ExtensionConverterManagerImpl getRegistrator() {
55         return registrator;
56     }
57     /**
58      * @return the key
59      */
60     public KEY getKey() {
61         return key;
62     }
63     /**
64      * @return the converter
65      */
66     public CONVERTER getConverter() {
67         return converter;
68     }
69     
70     @Override
71     public CONVERTER getInstance() {
72         return getConverter();
73     }
74     
75     /**
76      * standalone deregistrator
77      * @param <TO> target type of wrapped convertor
78      */
79     public static class RegistrationCloserToOFJava<TO extends DataContainer> extends 
80             RegistrationCloser<ConverterExtensionKey<? extends ExtensionKey>, ConvertorToOFJava<TO>> {
81         
82         @Override
83         public void close() throws Exception {
84             getRegistrator().unregister(getKey(), getConverter());
85         }
86     }
87     
88     /**
89      * standalone deregistrator
90      * @param <FROM> source type of wrapped convertor
91      * @param <PATH> associated augmentation path
92      */
93     public static class RegistrationCloserFromOFJava<FROM extends DataContainer, PATH extends AugmentationPath> extends RegistrationCloser<MessageTypeKey<?>, ConvertorFromOFJava<FROM, PATH>> {
94         
95         @Override
96         public void close() throws Exception {
97             getRegistrator().unregister(getKey(), getConverter());
98         }
99     }
100     
101     /**
102      * standalone deregistrator
103      * @param <TO> target type of wrapped convertor
104      */
105     public static class RegistrationCloserActionToOFJava<TO extends DataContainer> extends 
106             RegistrationCloser<TypeVersionKey<? extends Action>, ConvertorActionToOFJava<Action, TO>> {
107         
108         @Override
109         public void close() throws Exception {
110             getRegistrator().unregister(getKey(), getConverter());
111         }
112     }
113     
114     /**
115      * standalone deregistrator
116      * @param <FROM> source type of wrapped convertor
117      * @param <PATH> associated augmentation path
118      */
119     public static class RegistrationCloserActionFromOFJava<FROM extends DataContainer, PATH extends AugmentationPath> extends RegistrationCloser<MessageTypeKey<?>, ConvertorActionFromOFJava<FROM, PATH>> {
120         
121         @Override
122         public void close() throws Exception {
123             getRegistrator().unregister(getKey(), getConverter());
124         }
125     }
126 }