Commit 28c843d7 authored by cponcele's avatar cponcele
Browse files

Change java generator to allow type overriding

Fix bug in detection_rx/tx_transducer_index
parent a137e77c
......@@ -164,11 +164,6 @@
"name": "long_name",
"value": "Raw backscatter measurements (real part)"
},
{
"name": "scale_factor",
"value": "0.5",
"type": "float"
},
{
"name": "units",
"comment": "Use units appropriate for the data.",
......@@ -5173,7 +5168,7 @@
"ping_time",
"detection"
],
"type": "ushort",
"type": "short",
"attributes": [
{
"name": "long_name",
......@@ -5233,7 +5228,7 @@
"ping_time",
"detection"
],
"type": "ushort",
"type": "short",
"attributes": [
{
"name": "long_name",
......
......@@ -59,26 +59,26 @@ interface Nc4prototypes{
public enum DataType {
BOOLEAN("boolean", 1, boolean.class, false,Nc4prototypes.NC_BYTE),
BYTE("byte", 1, byte.class, false,Nc4prototypes.NC_BYTE),
CHAR("char", 1, char.class,false,Nc4prototypes.NC_CHAR),
SHORT("short", 2, short.class, false,Nc4prototypes.NC_SHORT),
INT("int", 4, int.class, false,Nc4prototypes.NC_INT),
BOOLEAN("boolean", 1, boolean.class, false,Nc4prototypes.NC_BYTE,"NC_BYTE"),
BYTE("byte", 1, byte.class, false,Nc4prototypes.NC_BYTE,"NC_BYTE"),
CHAR("char", 1, char.class,false,Nc4prototypes.NC_CHAR,"NC_CHAR"),
SHORT("short", 2, short.class, false,Nc4prototypes.NC_SHORT,"NC_SHORT"),
INT("int", 4, int.class, false,Nc4prototypes.NC_INT,"NC_INT"),
LONG("long", 8, long.class,
false,Nc4prototypes.NC_INT64),
FLOAT("float", 4, float.class, false,Nc4prototypes.NC_FLOAT),
DOUBLE("double", 8, double.class, false,Nc4prototypes.NC_DOUBLE),
false,Nc4prototypes.NC_INT64,"NC_INT64"),
FLOAT("float", 4, float.class, false,Nc4prototypes.NC_FLOAT,"NC_FLOAT"),
DOUBLE("double", 8, double.class, false,Nc4prototypes.NC_DOUBLE,"NC_DOUBLE"),
// object types
STRING("String", 4, String.class, false,Nc4prototypes.NC_STRING), // 32-bit index
ENUM1("enum1", 1, byte.class, false,Nc4prototypes.NC_BYTE), // byte
ENUM2("enum2", 2, short.class, false,Nc4prototypes.NC_SHORT), // short
ENUM4("enum4", 4, int.class, false,Nc4prototypes.NC_INT), // int
STRING("String", 4, String.class, false,Nc4prototypes.NC_STRING,"NC_STRING"), // 32-bit index
ENUM1("enum1", 1, byte.class, false,Nc4prototypes.NC_BYTE,"NC_BYTE"), // byte
ENUM2("enum2", 2, short.class, false,Nc4prototypes.NC_SHORT,"NC_SHORT"), // short
ENUM4("enum4", 4, int.class, false,Nc4prototypes.NC_INT,"NC_INT"), // int
// OPAQUE("opaque", 1, ByteBuffer.class, false), // byte blobs
// OBJECT("object", 1, Object.class, false,), // added for use with Array
UBYTE("ubyte", 1, byte.class, true,Nc4prototypes.NC_UBYTE),
USHORT("ushort", 2, short.class, true,Nc4prototypes.NC_USHORT),
UINT("uint", 4, int.class,true,Nc4prototypes.NC_UINT),
ULONG("ulong", 8, long.class, true,Nc4prototypes.NC_UINT64);
UBYTE("ubyte", 1, byte.class, true,Nc4prototypes.NC_UBYTE,"NC_UBYTE"),
USHORT("ushort", 2, short.class, true,Nc4prototypes.NC_USHORT,"NC_USHORT"),
UINT("uint", 4, int.class,true,Nc4prototypes.NC_UINT,"NC_UINT"),
ULONG("ulong", 8, long.class, true,Nc4prototypes.NC_UINT64,"NC_UINT64");
......@@ -87,6 +87,7 @@ public enum DataType {
private final Class<?> primitiveClass;
private final boolean isUnsigned;
private int nc_type;
private String nc_type_name;
/**
* Return the native nc_type associated with this enum
......@@ -95,12 +96,17 @@ public enum DataType {
return nc_type;
}
DataType(String s, int size, Class<?> primitiveClass, boolean isUnsigned,int nc_type) {
DataType(String s, int size, Class<?> primitiveClass, boolean isUnsigned,int nc_type, String nc_type_name) {
this.niceName = s;
this.size = size;
this.primitiveClass = primitiveClass;
this.isUnsigned = isUnsigned;
this.nc_type=nc_type;
this.nc_type_name = nc_type_name;
}
public String getNc_type_name() {
return nc_type_name;
}
/**
......
......@@ -10,7 +10,7 @@ public class SCDimensionAdapter {
* */
public static List<String> getSourceCode(Dimension dimension) {
String size = dimension.javaValue == null ? "100" : dimension.javaValue;
String size = dimension.javaValue == null ? "0" : dimension.javaValue;
return Arrays.asList(
String.format("\t\t%s = declareDimension(%s, %s); //%s", getDimCodeName(dimension.name), getDimNameDeclaration(dimension), size, dimension.comment==null ? "" : dimension.comment));
}
......
......@@ -61,16 +61,22 @@ public class SCGroupAdapter {
sourceCode.add("import java.util.ArrayList;");
sourceCode.add("import java.util.Arrays;\n");
sourceCode.add("import java.util.HashMap;\n");
sourceCode.add("import java.util.Arrays;\n");
;
// Get import and layer declaration lines
SortedSet<String> classToImportSet = new TreeSet<>();
classToImportSet.add("import fr.ifremer.globe.api.xsf.converter.common.sounder.ISounderFile;");
classToImportSet.add("import fr.ifremer.globe.netcdf.jna.Nc4prototypes;");
classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.DataType;");
classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCException;");
classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCGroup;");
classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCVariable;");
classToImportSet.add("import fr.ifremer.globe.netcdf.util.Pair;");
if (!group.variables.isEmpty())
classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCVariable;");
classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCVariable;");
classToImportSet.add("import fr.ifremer.globe.netcdf.ucar.NCDimension;");
......@@ -117,13 +123,23 @@ public class SCGroupAdapter {
// Start constructor if not a sensor
switch (group.getGroupCategory()) {
case eStandard:
sourceCode.add(String.format("\n\t/**\r\n"
+ "\t* Constructor for %s \r\n"
+ "\t* @param \r\n"
+ "\t* typeDictionnary a dictonnary of type definition, if not found the default ones will be used\r\n"
+ "\t* */",getClassName(group, "")));
sourceCode.add(String.format(
"\n\tpublic %s(NCGroup parent, ISounderFile dataProxy) throws NCException {\n\t\tsuper(GROUP_NAME,parent);",
"\tpublic %s(NCGroup parent, ISounderFile dataProxy,HashMap<String,Integer> typeDictionnary) throws NCException {\n\t\tsuper(GROUP_NAME,parent);",
getClassName(group, "")));
break;
case eSensor:
sourceCode.add(String.format("\n\t/**\r\n"
+ "\t* Constructor for %s \r\n"
+ "\t* @param \r\n"
+ "\t* typeDictionnary a dictonnary of type definition, if not found the default ones will be used\r\n"
+ "\t* */",getClassName(group, "")));
sourceCode.add(String.format(
"\n\tpublic %s(NCGroup parent, ISounderFile dataProxy, String id) throws NCException {\n\t\tsuper(id,parent);",
"\tpublic %s(NCGroup parent, ISounderFile dataProxy, String id,HashMap<String,Integer> typeDictionnary) throws NCException {\n\t\tsuper(id,parent);",
getClassName(group, "")));
break;
......@@ -179,7 +195,7 @@ public class SCGroupAdapter {
if (!group.dims.isEmpty()) {
sourceCode.add("\t/**\n" + "\t* declare a dimension is its lenght is strictly positive\n" + "\t**/\n"
+ "\tprivate NCDimension declareDimension(String dimName, long len) throws NCException {\n"
+ "\t\t if(len <= 0) return null; //dimension is considered as not defined (optional) in this file\n"
+ "\t\t if(len < 0) return null; //dimension is considered as not defined (optional) in this file\n"
+ "\t\t return addDimension(dimName, len);\n" + "\t}\n");
}
// Coordinate variables Accessors
......
......@@ -13,7 +13,7 @@ public class SCTypeAdapter {
{
DataType type;
type = DataTypeConverter.getVlenDataType(name);
return Arrays.asList(String.format("\t\tthis.addType(\"%s\",%d); //vlen for type %s",name,type.getNc_type(),type));
return Arrays.asList(String.format("\t\tthis.addType(\"%s\",typeDictionnary.getOrDefault(\"sample_t\",Nc4prototypes.%s)); //vlen for type %s",name,type.getNc_type_name(),type));
} else if (name.contains("enum"))
{
return parseEnum(name);
......
......@@ -2,7 +2,7 @@ package fr.ifremer.fr.xsf.generator.model;
public class Type extends Base {
public Type(String name, String description, String comment, String obligation) {
public Type(String name, String description, String comment, String obligation, String xsfOverride) {
super(name, description, comment, obligation);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment