Fixed compilation issues due to changes in other projects
[groupbasedpolicy.git] / groupbasedpolicy / src / main / java / org / opendaylight / groupbasedpolicy / util / IetfModelCodec.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.groupbasedpolicy.util;
10
11 import javax.annotation.Nullable;
12
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
21
22 /**
23  * This is temporary solution for conversion between entities from
24  * ietf-{inet,yang}-types 2013 to ietf-{inet,yang}-types 2010 and vice versa.
25  * This conversion should be removed after GBP and all other projects migrate to version 2013.
26  */
27 public final class IetfModelCodec {
28
29     private IetfModelCodec() {}
30
31     public static @Nullable IpPrefix ipPrefix2010(
32             @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix ip) {
33         if (ip == null) {
34             return null;
35         }
36         if (ip.getIpv4Prefix() != null) {
37             return new IpPrefix(ipv4Prefix2010(ip.getIpv4Prefix()));
38         } else if (ip.getIpv6Prefix() != null) {
39             return new IpPrefix(ipv6Prefix2010(ip.getIpv6Prefix()));
40         }
41         throw new IllegalArgumentException("IP prefix is not ipv4 nor ipv6. " + ip);
42     }
43
44     public static @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix ipPrefix2013(
45             @Nullable IpPrefix ip) {
46         if (ip == null) {
47             return null;
48         }
49         if (ip.getIpv4Prefix() != null) {
50             return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix(
51                     ipv4Prefix2013(ip.getIpv4Prefix()));
52         } else if (ip.getIpv6Prefix() != null) {
53             return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix(
54                     ipv6Prefix2013(ip.getIpv6Prefix()));
55         }
56         throw new IllegalArgumentException("IP prefix is not ipv4 nor ipv6. " + ip);
57     }
58
59     public static @Nullable Ipv4Prefix ipv4Prefix2010(
60             @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix ip) {
61         if (ip == null) {
62             return null;
63         }
64         return new Ipv4Prefix(ip.getValue());
65     }
66
67     public static @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix ipv4Prefix2013(
68             @Nullable Ipv4Prefix ip) {
69         if (ip == null) {
70             return null;
71         }
72         return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix(
73                 ip.getValue());
74     }
75
76     public static @Nullable Ipv6Prefix ipv6Prefix2010(
77             @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix ip) {
78         if (ip == null) {
79             return null;
80         }
81         return new Ipv6Prefix(ip.getValue());
82     }
83
84     public static @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix ipv6Prefix2013(
85             @Nullable Ipv6Prefix ip) {
86         if (ip == null) {
87             return null;
88         }
89         return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix(
90                 ip.getValue());
91     }
92
93     public static @Nullable MacAddress macAddress2010(
94             @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress mac) {
95         if (mac == null) {
96             return null;
97         }
98         return new MacAddress(mac.getValue());
99     }
100
101     public static @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress macAddress2013(
102             @Nullable MacAddress mac) {
103         if (mac == null) {
104             return null;
105         }
106         return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress(
107                 mac.getValue());
108     }
109
110     public static @Nullable IpAddress ipAddress2010(
111             @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress ip) {
112         if (ip == null) {
113             return null;
114         }
115         if (ip.getIpv4Address() != null) {
116             return new IpAddress(ipv4Address2010(ip.getIpv4Address()));
117         } else if (ip.getIpv6Address() != null) {
118             return new IpAddress(ipv6Address2010(ip.getIpv6Address()));
119         }
120         throw new IllegalArgumentException("IP address is not ipv4 nor ipv6. " + ip);
121     }
122
123     public static @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress ipAddress2013(
124             @Nullable IpAddress ip) {
125         if (ip == null) {
126             return null;
127         }
128         if (ip.getIpv4Address() != null) {
129             return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress(
130                     ipv4Address2013(ip.getIpv4Address()));
131         } else if (ip.getIpv6Address() != null) {
132             return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress(
133                     ipv6Address2013(ip.getIpv6Address()));
134         }
135         throw new IllegalArgumentException("IP address is not ipv4 nor ipv6. " + ip);
136     }
137
138     public static @Nullable Ipv4Address ipv4Address2010(
139             @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address ip) {
140         if (ip == null) {
141             return null;
142         }
143         return new Ipv4Address(ip.getValue());
144     }
145
146     public static @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address ipv4Address2013(
147             @Nullable Ipv4Address ip) {
148         if (ip == null) {
149             return null;
150         }
151         return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address(
152                 ip.getValue());
153     }
154
155     public static @Nullable Ipv6Address ipv6Address2010(
156             @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address ip) {
157         if (ip == null) {
158             return null;
159         }
160         return new Ipv6Address(ip.getValue());
161     }
162
163     public static @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address ipv6Address2013(
164             @Nullable Ipv6Address ip) {
165         if (ip == null) {
166             return null;
167         }
168         return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address(
169                 ip.getValue());
170     }
171
172     public static @Nullable PortNumber portNumber2010(
173             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber pn) {
174         if (pn == null) {
175             return null;
176         }
177         return new PortNumber(pn.getValue());
178     }
179 }