All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.DataInterface.vtl Maven / Gradle / Ivy

package ${group.packageName};

/*-
 * #%L
 * ncml-io
 * %%
 * Copyright (C) 2020 - 2021 Henrique L. F. de Sousa
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

// imports >>
#if ($customContent.imports)
${customContent.imports}##
#else
import io.github.hlfsousa.ncml.annotation.*;
import io.github.hlfsousa.ncml.declaration.*;
import java.util.*;
import ucar.ma2.Array;
#end
// << imports

#if($group.class.simpleName == "SchemaWrapper")
@CDLRoot
#end
@CDLDimensions({
#foreach($dimension in $group.dimensions)
  #set($dimLength = 0)
  #if($dimension.length)
    #set($dimLength = $dimension.length)
  #end
        @CDLDimension(name = "${escapeString.apply($dimension.name)}"#if($dimLength > 0), length = ${dimLength}#end#if($dimension.isUnlimited), unlimited = true#end)#if($foreach.hasNext),#end
#end
})
public interface ${group.typeName} {
#set($reservedWords = [ "case", "switch", "enum", "if", "class", "interface" ])
#macro(findType $type $isArray)
  #set($unsigned = false)
  #set($primitive = false)
  #if($type == "string" || $type == "String")
    #set($typeName = "String")
  #elseif($type == "byte" || $type == "ubyte")
    #set($typeName = "Byte")
    #set($unsigned = $type.charAt(0) == 'u')
    #set($primitive = true)
  #elseif($type == "char")
    #if ($isArray)
      #set($primitive = true)
      #set($typeName = "char")
    #else
      #set($typeName = "Character")
    #end
    #set($primitive = true)
  #elseif($type == "short" || $type == "ushort")
    #set($typeName = "Short")
    #set($unsigned = $type.charAt(0) == 'u')
    #set($primitive = true)
  #elseif($type == "int" || $type == "uint")
    #if ($isArray)
      #set($primitive = true)
      #set($typeName = "int")
    #else
      #set($typeName = "Integer")
    #end
    #set($unsigned = $type.charAt(0) == 'u')
  #elseif($type == "long" || $type == "ulong")
    #set($typeName = "Long")
    #set($unsigned = $type.charAt(0) == 'u')
    #set($primitive = true)
  #elseif($type == "float")
    #if ($isArray)
      #set($primitive = true)
      #set($typeName = "float")
    #else
      #set($typeName = "Float")
    #end
  #elseif($type == "double")
    #if ($isArray)
      #set($primitive = true)
      #set($typeName = "double")
    #else
      #set($typeName = "Double")
    #end
  #elseif($type == "Structure")
    #set($typeName = "Object") // TODO locate type
  #elseif($type == "Sequence")
    #set($typeName = "") // TODO Sequence
  #elseif($type == "opaque")
    #set($typeName = "Object") // TODO locate type
  #elseif($type == "enum1")
    #set($typeName = "") // TODO locate enumTypedef
  #elseif($type == "enum2")
    #set($typeName = "") // TODO locate enumTypedef
  #elseif($type == "enum4")
    #set($typeName = "") // TODO locate enumTypedef
  #end
  #if($primitive && $isArray)
    #set($typeName = $typeName.toLowerCase())
  #end
#end
## INNER INTERFACE (VARIABLES WITH ATTRIBUTES)
#foreach($variable in $group.variables)
  #if(!$variable.dimensions.empty || !$variable.attributes.empty)
    interface ${variable.typeName}Variable extends Variable {

    #foreach($attributeWrapper in $variable.attributes)
      #set($attribute = $attributeWrapper.attribute)
      #set($accessor = "get" + $attributeWrapper.camelCase($attributeWrapper.name))
      #set($modifier = "set" + $attributeWrapper.camelCase($attributeWrapper.name))
      #set($localVar = $attributeWrapper.dromedaryCase($attributeWrapper.name))
      #if($reservedWords.contains($localVar))
        #set($localVar = "_" + $localVar)
      #end
      #set($arrayAttribute = !$attributeWrapper.shapeBrackets.empty)
      #findType($attribute.type $arrayAttribute)
      #set($localType = $typeName + $attributeWrapper.shapeBrackets)
      #if($arrayAttribute)
        #set($localType = "Array")
      #end
        @CDLAttribute(name = "${escapeString.apply($attribute.name)}", dataType = "${attribute.type}"#if($attribute.value), defaultValue = "${escapeString.apply($attribute.value)}"#end)
        ${localType} ${accessor}();

        void ${modifier}(${localType} ${localVar});

    #end
    }

  #end
#end
## ATTRIBUTES
#foreach($attributeWrapper in $group.attributes)
  #set($attribute = $attributeWrapper.attribute)
  #set($accessor = "get" + $attributeWrapper.camelCase($attributeWrapper.name))
  #set($modifier = "set" + $attributeWrapper.camelCase($attributeWrapper.name))
  #set($localVar = ${attributeWrapper.dromedaryCase($attributeWrapper.name)})
  #if($reservedWords.contains($localVar))
    #set($localVar = "_" + $localVar)
  #end
  #set($arrayAttribute = !$attributeWrapper.shapeBrackets.empty)
  #findType($attribute.type $arrayAttribute)
  #set($localType = $typeName + $attributeWrapper.shapeBrackets)
  #if($arrayAttribute)
    #set($localType = "Array")
  #end
    @CDLAttribute(name = "${escapeString.apply($attribute.name)}", dataType = "${attribute.type}"#if($attribute.value), defaultValue = "${escapeString.apply($attribute.value)}"#end)
    ${localType} ${accessor}();

    void ${modifier}(${localType} ${localVar});

#end
## VARIABLES
#foreach($varWrapper in $group.variables)
  #set($variable = $varWrapper.variable)
  #set($accessor = "get" + $varWrapper.camelCase($varWrapper.name))
  #set($modifier = "set" + $varWrapper.camelCase($varWrapper.name))
  #set($localVar = $varWrapper.dromedaryCase($varWrapper.name))
  #set($arrayVariable = !$varWrapper.shapeBrackets.empty)
  #findType($variable.type $arrayVariable)
  #set($rawType = $typeName)
  #findType($varWrapper.scaledType $arrayVariable)
  #set($propType = $typeName)
    @CDLVariable(name = "${escapeString.apply($variable.name)}", type = ${rawType}.class, unsigned = ${unsigned}#if($variable.shape), shape = { #foreach($dimension in $variable.shape.split(" "))"${dimension}"#if($foreach.hasNext), #end#end }#end)
  #if(!$variable.attribute.empty || !$varWrapper.dimensions.empty)
    #if($varWrapper.mapped)
      #if($variable.shape)
        #set($propType = "Map>")
      #else
        #set($propType = "Map>")
      #end
    #else
      #if($variable.shape)
        #set($propType = $varWrapper.typeName + "Variable")
      #else
        #set($propType = $varWrapper.typeName + "Variable<" + $typeName + ">")
      #end
    #end
  #else
    #if($varWrapper.mapped)
      #if($variable.shape)
        #set($propType = "Map")
      #else
        #set($propType = "Map")
      #end
    #else
      #if($variable.shape)
        #set($propType = "Array")
      #else
        #set($propType = $typeName)
      #end
    #end
  #end
    ${propType} ${accessor}();

    void ${modifier}(${propType} ${localVar});

#end
## GROUPS
#foreach($childGroup in $group.groups)
  #set($typeName = $childGroup.camelCase($childGroup.typeName))
  #set($accessor = "get" + $childGroup.camelCase($childGroup.name))
  #set($modifier = "set" + $childGroup.camelCase($childGroup.name))
    @CDLGroup(name = "${escapeString.apply($childGroup.nameTag)}")
  #if($childGroup.mapped)
    Map ${accessor}();

    void ${modifier}(Map ${childGroup.dromedaryCase($childGroup.name)});
  #else
    ${typeName} ${accessor}();

    void ${modifier}(${typeName} ${childGroup.dromedaryCase($childGroup.name)});
  #end

#end
    // methods >>
$!{customContent.methods}##
    // << methods

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy