Bug 1459-1 - Re-organize mdsal-binding2-spec
[mdsal.git] / binding2 / mdsal-binding2-java-api-generator / src / main / twirl / org / opendaylight / mdsal / binding2 / classTemplateConstructors.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.java.api.generator.util.TextTemplateUtil.asArguments
10 @import org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.fieldName
11 @import org.opendaylight.mdsal.binding2.model.api.GeneratedTransferObject
12 @import org.opendaylight.mdsal.binding2.model.api.GeneratedProperty
13 @import org.opendaylight.mdsal.binding2.util.BindingMapping.PATTERN_CONSTANT_NAME
14
15 @(genTo: GeneratedTransferObject, allProperties: List[GeneratedProperty], properties: List[GeneratedProperty],
16 parentProperties: List[GeneratedProperty], importedNames: Map[String, String], argumentsDeclaration: String,
17 unionConstructor: String, genRestrictions: String)
18 @if(unionConstructor != null) {
19 @{unionConstructor}
20 } else {
21     @if(genTo.isTypedef && !allProperties.isEmpty && allProperties.size == 1 && allProperties.get(0).getName.equals("value")) {
22         @@@{importedNames.get("constructorProperties")}("value")
23     }
24     public @{genTo.getName}(@{argumentsDeclaration}) {
25         @if(!parentProperties.isEmpty) {
26             super(@{asArguments(parentProperties)});
27         }
28
29         @{genRestrictions}
30
31         @if(genTo.isTypedef && !allProperties.isEmpty && allProperties.size == 1 && allProperties.get(0).getName.equals("value")) {
32         @{importedNames.get("preconditions")}.checkNotNull(_value, "Supplied value may not be null");
33             @for(currentConstant <- genTo.getConstantDefinitions) {
34                 @if(PATTERN_CONSTANT_NAME.equals(currentConstant.getName) && currentConstant.getValue.isInstanceOf[List[_]]) {
35                     for (Pattern p : patterns) {
36                         @{importedNames.get("preconditions")}.checkArgument(p.matcher(_value).matches(), "Supplied value \"%s\" does not match required pattern \"%s\"", _value, p);
37                     }
38                 }
39             }
40         }
41         @for(prop <- properties) {
42             @if(importedNames.get(prop.getReturnType.toString).contains("[]")) {
43                 @if(genTo.isTypedef && !allProperties.isEmpty && allProperties.size == 1 && allProperties.get(0).getName.equals("value")) {
44                     this.@{fieldName(prop)} = @{fieldName(prop)}.clone();
45                 } else {
46                     this.@{fieldName(prop)} = @{fieldName(prop)} == null ? null : @{fieldName(prop)}.clone();
47                 }
48             } else {
49                 this.@{fieldName(prop)} = this.@{fieldName(prop)};
50             }
51         }
52     }
53 }
54 @if(!allProperties.isEmpty) {
55     /**
56      * Creates a copy from Source Object.
57      *
58      * @@param source Source object
59      */
60     public @{genTo.getName}(@{genTo.getName} source) {
61         @if(!parentProperties.isEmpty) {
62             super(source);
63         }
64         @for(property <- properties) {
65             this.@{fieldName(property)} = source.@{fieldName(property)};
66         }
67     }
68 }
69 @if(properties.isEmpty && !parentProperties.isEmpty) {
70     /**
71      * Creates a new instance from @{importedNames.get("superType")}
72      *
73      * @@param source Source object
74      */
75     public @{genTo.getName}(@{importedNames.get("superType")} source) {
76             super(source);
77     }
78 }