Bug 6112 - UnionTypeCodec fails to non-identityref value
[mdsal.git] / binding / mdsal-binding-test-model / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / mdsal / test / bug / _6006 / rev160607 / UnionTypeBuilder.java
1 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607;
2
3 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.IdentBase;
4 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.IdentOne;
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.IdentTwo;
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 UnionTypeBuilder {
17
18     public static UnionType getDefaultInstance(java.lang.String defaultValue) {
19         if (defaultValue.equals("IdentOne")) {
20             return new UnionType(IdentOne.class);
21         }
22         if (defaultValue.equals("IdentTwo")) {
23             return new UnionType(IdentTwo.class);
24         }
25
26         try {
27             return new UnionType(Short.valueOf(defaultValue));
28         } catch(NumberFormatException e) {
29             /* do nothing */;
30         }
31
32         throw new IllegalArgumentException("Unknown UnionType string " + defaultValue);
33     }
34
35 }