Bug 1411-5 #8: MDSAL Binding2 Java API Generator
[mdsal.git] / binding2 / mdsal-binding2-java-api-generator / src / main / twirl / org / opendaylight / mdsal / binding2 / unionTemplate.scala.txt
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 @import org.opendaylight.mdsal.binding2.model.api.GeneratedType
10 @import org.opendaylight.mdsal.binding2.model.api.GeneratedProperty
11 @import org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.fieldName
12 @import org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.asArguments
13 @import org.opendaylight.mdsal.binding2.generator.util.Types.getOuterClassName
14
15 @(baseType: GeneratedType, importedNames: Map[String, String], finalProperties: List[GeneratedProperty],
16 parentProperties: List[GeneratedProperty], properties: List[GeneratedProperty], propertyList: String)
17 @for(property <- parentProperties) {
18     public @{baseType.getName}(@{importedNames.get(property.getName)} @{fieldName(property)}) {
19         super(@{fieldName(property)});
20     }
21 }
22 @for(property <- finalProperties) {
23     @if("char[]".equals(property.getReturnType.getName)) {
24     /**
25      * Constructor provided only for using in JMX. Don't use it for
26      * construction new object of this union type.
27      */
28     @@@{importedNames.get("constructorProperties")}("@{property.getName}")
29     public @{baseType.getName}({importedNames.get(property.getName)} @{fieldName(property)}) {
30         @{importedNames.get("string")} defVal = new @{importedNames.get("string")}(@{fieldName(property)});
31         @{baseType.getName} defInst = @{typeBuilder}.getDefaultInstance(defVal);
32         @for(otherProperty <- finalProperties) {
33             this.@{fieldName(otherProperty)} =
34             @if("value".equals(otherProperty.getName)) {
35                 @if(importedNames.get(otherProperty.getName).contains("[]")) {
36                     @{fieldName(otherProperty)} == null ? null : @{fieldName(otherProperty)}.clone();
37                 } else {
38                     @{fieldName(otherProperty)};
39                 }
40             } else {
41                 defInst.@{fieldName(otherProperty)};
42             }
43         }
44     }
45     } else {
46         @*TO DO parentProperties + #[property] as argument to method below see  unionTemplate 84 *@
47         public @{baseType.getName}() {
48             super(@{asArguments(parentProperties)});
49             this.@{fieldName(property)} = @{fieldName(property)};
50             @for(otherProperty <- finalProperties) {
51                 @if(property != otherProperty && !"value".equals(otherProperty.getName)) {
52                     this.@{fieldName(otherProperty)} = null;
53                 }
54             }
55         }
56     }
57 }
58 @if(!properties.isEmpty && !parentProperties.isEmpty) {
59     /**
60      * Creates a copy from Source Object.
61      *
62      * @@param source Source object
63      */
64     public @{baseType.getName}
65     (@{baseType.getName}
66      source) {
67     @if(!parentProperties.isEmpty()) {super(source);}
68     @{propertyList}
69     }
70 }
71 @if(properties.isEmpty && !parentProperties.isEmpty) {
72     /**
73      * Creates a new instance from @{importedNames.get("superType")}
74      *
75      * @@param source Source object
76      */
77     public @{baseType.getName}(@{importedNames.get("superType")} source) {
78             super(source);
79     }
80 }
81
82 @typeBuilder() = {
83 @if(getOuterClassName(baseType) != null) {
84     @{getOuterClassName(baseType)}@{baseType.getName}Builder
85 } else {
86     @{baseType.getName}Builder
87 }
88 }