2 * Copyright (c) 2014 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
8 package org.opendaylight.yangtools.sal.java.api.generator
10 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
11 import java.beans.ConstructorProperties
14 * Template for generating JAVA class.
16 class UnionTemplate extends ClassTemplate {
19 * Creates instance of this class with concrete <code>genType</code>.
21 * @param genType generated transfer object which will be transformed to JAVA class source code
23 new(GeneratedTransferObject genType) {
27 override constructors() '''
28 «unionConstructorsParentProperties»
30 «IF !allProperties.empty»
33 «IF properties.empty && !parentProperties.empty»
38 private def unionConstructors() '''
39 «FOR property : finalProperties SEPARATOR "\n"»
40 «val isCharArray = "char[]".equals(property.returnType.name)»
43 * Constructor provided only for using in JMX. Don't use it for
44 * construction new object of this union type.
46 @«ConstructorProperties.importedName»("«property.name»")
47 public «type.name»(«property.returnType.importedName» «property.fieldName») {
48 «String.importedName» defVal = new «String.importedName»(«property.fieldName»);
49 «type.name» defInst = «type.name»Builder.getDefaultInstance(defVal);
50 «FOR other : finalProperties»
51 «IF other.name.equals("value")»
52 this.«other.fieldName» = «other.fieldName»;
54 this.«other.fieldName» = defInst.«other.fieldName»;
59 «val propertyAndTopParentProperties = parentProperties + #[property]»
60 public «type.name»(«propertyAndTopParentProperties.asArgumentsDeclaration») {
61 super(«parentProperties.asArguments»);
62 this.«property.fieldName» = «property.fieldName»;
63 «FOR other : finalProperties»
64 «IF property != other»this.«other.fieldName» = null;«ENDIF»
71 private def unionConstructorsParentProperties() '''
72 «FOR property : parentProperties SEPARATOR "\n"»
73 public «type.name»(«property.returnType.importedName» «property.fieldName») {
74 super(«property.fieldName»);
79 override protected copyConstructor() '''
81 * Creates a copy from Source Object.
83 * @param source Source object
85 public «type.name»(«type.name» source) {
86 «IF !parentProperties.empty»
89 «IF !properties.empty»
91 this.«p.fieldName» = source.«p.fieldName»;