Add ietf-lisp-address-types model
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / lisp / address / types / rev151105 / SimpleAddressBuilder.java
1 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105;
2
3 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
4 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder;
5 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
6
7
8 /**
9  * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
10  * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
11  *
12  * The reason behind putting it under src/main/java is:
13  * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
14  * loss of user code.
15  *
16  */
17 public class SimpleAddressBuilder {
18
19     public static SimpleAddress getDefaultInstance(String defaultValue) {
20         SimpleAddress address = tryIpAddress(defaultValue);
21         if (address != null) {
22             return address;
23         }
24
25         address = tryIpPrefix(defaultValue);
26         if (address != null) {
27             return address;
28         }
29
30         address = tryMacAddress(defaultValue);
31         if (address != null) {
32             return address;
33         }
34
35         // XXX need support for MAC addresses and AS numbers
36         address = new SimpleAddress(new DistinguishedNameType(defaultValue));
37
38         return address;
39     }
40
41     private static SimpleAddress tryIpAddress(String defaultValue) {
42         try {
43             SimpleAddress address = new SimpleAddress(IpAddressBuilder.getDefaultInstance(defaultValue));
44             return address;
45         } catch (IllegalArgumentException e) {
46             return null;
47         }
48     }
49
50     private static SimpleAddress tryIpPrefix(String defaultValue) {
51         try {
52             SimpleAddress address = new SimpleAddress(IpPrefixBuilder.getDefaultInstance(defaultValue));
53             return address;
54         } catch (IllegalArgumentException e) {
55             return null;
56         }
57     }
58
59     private static SimpleAddress tryMacAddress(String defaultValue) {
60         try {
61             SimpleAddress address = new SimpleAddress(new MacAddress(defaultValue));
62             return address;
63         } catch (IllegalArgumentException e) {
64             return null;
65         }
66     }
67 }