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