2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
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
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) {
21 @if(genTo.isTypedef && !allProperties.isEmpty && allProperties.size == 1 && allProperties.get(0).getName.equals("value")) {
22 @@@{importedNames.get("constructorProperties")}("value")
24 public @{genTo.getName}(@{argumentsDeclaration}) {
25 @if(!parentProperties.isEmpty) {
26 super(@{asArguments(parentProperties)});
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);
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();
46 this.@{fieldName(prop)} = @{fieldName(prop)} == null ? null : @{fieldName(prop)}.clone();
49 this.@{fieldName(prop)} = this.@{fieldName(prop)};
54 @if(!allProperties.isEmpty) {
56 * Creates a copy from Source Object.
58 * @@param source Source object
60 public @{genTo.getName}(@{genTo.getName} source) {
61 @if(!parentProperties.isEmpty) {
64 @for(property <- properties) {
65 this.@{fieldName(property)} = source.@{fieldName(property)};
69 @if(properties.isEmpty && !parentProperties.isEmpty) {
71 * Creates a new instance from @{importedNames.get("superType")}
73 * @@param source Source object
75 public @{genTo.getName}(@{importedNames.get("superType")} source) {