this.cellwidth = -1; // yet undefined
} else if (typename.equals("Bitfield")) {
this.celltype = celltype_bitfield;
this.cellwidth = -1; // yet undefined
} else {
throw new kelondroException("kelondroColumn - undefined type def '" + typename + "'");
}
}
// parse length
p = celldef.indexOf('-');
if (p < 0) {
// if the cell was defined with a type, we dont need to give an explicit with definition
if (this.cellwidth < 0) throw new kelondroException("kelondroColumn - no cell width definition given");
final int q = celldef.indexOf(' ');
if (q < 0) {
this.nickname = celldef;
celldef = "";
} else {
this.nickname = celldef.substring(0, p);
celldef = celldef.substring(q + 1);
}
} else {
this.nickname = celldef.substring(0, p);
final int q = celldef.indexOf(' ');
if (q < 0) {
try {
this.cellwidth = Integer.parseInt(celldef.substring(p + 1));
} catch (final NumberFormatException e) {
throw new kelondroException("kelondroColumn - cellwidth description wrong:" + celldef.substring(p + 1));
}
celldef = "";
} else {
try {
this.cellwidth = Integer.parseInt(celldef.substring(p + 1, q));
} catch (final NumberFormatException e) {
throw new kelondroException("kelondroColumn - cellwidth description wrong:" + celldef.substring(p + 1, q));
}
celldef = celldef.substring(q + 1);
}
}
// check length constraints
if (this.cellwidth < 0) throw new kelondroException("kelondroColumn - no cell width given for " + this.nickname);
if (((typename.equals("boolean")) && (this.cellwidth > 1)) ||
((typename.equals("byte")) && (this.cellwidth > 1)) ||
((typename.equals("short")) && (this.cellwidth > 2)) ||
((typename.equals("int")) && (this.cellwidth > 4)) ||
((typename.equals("long")) && (this.cellwidth > 8)) ||
((typename.equals("char")) && (this.cellwidth > 1))
) throw new kelondroException("kelondroColumn - cell width " + this.cellwidth + " too wide for type " + typename);
/*
if (((typename.equals("short")) && (this.cellwidth <= 1)) ||
((typename.equals("int")) && (this.cellwidth <= 2)) ||
((typename.equals("long")) && (this.cellwidth <= 4))
) throw new kelondroException("kelondroColumn - cell width " + this.cellwidth + " not appropriate for type " + typename);
*/
// parse/check encoder type
if (celldef.length() > 0 && celldef.charAt(0) == '{') {
p = celldef.indexOf('}');
final String expf = celldef.substring(1, p);
celldef = celldef.substring(p + 1).trim();
if (expf.equals("b64e")) this.encoder = encoder_b64e;
else if (expf.equals("b256")) this.encoder = encoder_b256;
else if (expf.equals("bytes")) this.encoder = encoder_bytes;
else {
if (this.celltype == celltype_undefined) this.encoder = encoder_bytes;
else if (this.celltype == celltype_boolean) this.encoder = encoder_bytes;
else if (this.celltype == celltype_binary) this.encoder = encoder_bytes;
else if (this.celltype == celltype_string) this.encoder = encoder_bytes;
else throw new kelondroException("kelondroColumn - encoder missing for cell '" + this.nickname + "'");
}
} else {
if (this.celltype == celltype_cardinal) throw new kelondroException("kelondroColumn - encoder missing for cell " + this.nickname);
this.encoder = encoder_bytes;
}
assert (this.celltype != celltype_cardinal) || (this.encoder == encoder_b64e) || (this.encoder == encoder_b256);