import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
import java.beans.ConstructorProperties
import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
+import static org.opendaylight.yangtools.binding.generator.util.Types.*
/**
- * Template for generating JAVA class.
+ * Template for generating JAVA class.
*/
class UnionTemplate extends ClassTemplate {
/**
* Creates instance of this class with concrete <code>genType</code>.
- *
+ *
* @param genType generated transfer object which will be transformed to JAVA class source code
*/
new(GeneratedTransferObject genType) {
«IF isCharArray»
/**
* Constructor provided only for using in JMX. Don't use it for
- * construction new object of this union type.
+ * construction new object of this union type.
*/
@«ConstructorProperties.importedName»("«property.name»")
public «type.name»(«propRet.importedName» «property.fieldName») {
«String.importedName» defVal = new «String.importedName»(«property.fieldName»);
- «type.name» defInst = «type.name»Builder.getDefaultInstance(defVal);
+ «type.name» defInst = «typeBuilder()».getDefaultInstance(defVal);
«FOR other : finalProperties»
«IF other.name.equals("value")»
+ «IF other.returnType.importedName.contains("[]")»
+ this.«other.fieldName» = «other.fieldName» == null ? null : «other.fieldName».clone();
+ «ELSE»
this.«other.fieldName» = «other.fieldName»;
+ «ENDIF»
«ELSE»
this.«other.fieldName» = defInst.«other.fieldName»;
«ENDIF»
«ELSEIF propRet instanceof GeneratedTransferObject && (propRet as GeneratedTransferObject).unionType»
««« union type
this.«other.fieldName» = «property.fieldName».getValue();
+ «ELSEIF propRet instanceof GeneratedTransferObject // Is it a GeneratedTransferObject
+ && (propRet as GeneratedTransferObject).typedef // Is it a typedef
+ && (propRet as GeneratedTransferObject).properties != null
+ && !(propRet as GeneratedTransferObject).properties.empty
+ && ((propRet as GeneratedTransferObject).properties.size == 1)
+ && (propRet as GeneratedTransferObject).properties.get(0).name.equals("value")
+ && BOOLEAN.equals((propRet as GeneratedTransferObject).properties.get(0).returnType)» // And the property value is of type boolean
+ ««« generated boolean typedef
+ this.«other.fieldName» = «property.fieldName».isValue().toString().toCharArray();
«ELSE»
««« generated type
this.«other.fieldName» = «property.fieldName».getValue().toString().toCharArray();
«ENDIF»
«ENDFOR»
'''
+
+ def typeBuilder() {
+ val outerCls = getOuterClassName(type);
+ if(outerCls !== null) {
+ return outerCls + type.name + "Builder"
+ }
+ return type.name + "Builder"
+ }
private def unionConstructorsParentProperties() '''
«FOR property : parentProperties SEPARATOR "\n"»
«ENDIF»
«IF !properties.empty»
«FOR p : properties»
+ «IF p.returnType.importedName.contains("[]")»
+ this.«p.fieldName» = source.«p.fieldName» == null ? null : source.«p.fieldName».clone();
+ «ELSE»
this.«p.fieldName» = source.«p.fieldName»;
+ «ENDIF»
«ENDFOR»
«ENDIF»
}