use of org.openmuc.jasn1.compiler.model.AsnObjectIdentifier in project jasn1 by openmuc.
the class BerClassWriter method writeOidValues.
private void writeOidValues(AsnModule module) throws IOException {
boolean first = true;
List<String> values = new ArrayList<>(module.asnValueAssignmentsByName.keySet());
Collections.sort(values);
for (String valueName : values) {
if (module.asnValueAssignmentsByName.get(valueName).type instanceof AsnObjectIdentifier) {
BerObjectIdentifier oid;
try {
oid = parseObjectIdentfierValue(valueName, module);
} catch (IllegalStateException e) {
System.out.println("Warning: could not parse object identifier value: " + e.getMessage());
continue;
}
StringBuilder sb = new StringBuilder("public static final BerObjectIdentifier " + cleanUpName(valueName) + " = new BerObjectIdentifier(new int[]{");
if (first == true) {
first = false;
writeClassHeader("OidValues", module);
write("public final class OidValues {");
}
boolean firstOidComponent = true;
for (int i : oid.value) {
if (firstOidComponent) {
firstOidComponent = false;
} else {
sb.append(", ");
}
sb.append(i);
}
sb.append("});");
write(sb.toString());
}
}
if (first == false) {
write("}");
out.close();
}
}
use of org.openmuc.jasn1.compiler.model.AsnObjectIdentifier in project jasn1 by openmuc.
the class BerClassWriter method parseObjectIdentfierValue.
private BerObjectIdentifier parseObjectIdentfierValue(String name, AsnModule module) throws IOException {
AsnValueAssignment valueAssignment = module.asnValueAssignmentsByName.get(name);
if (valueAssignment == null || !(valueAssignment.type instanceof AsnObjectIdentifier)) {
return null;
// throw new IOException(
// "no object identifier named \"" + name + "\" in module \"" + module.moduleIdentifier.name);
}
if (!valueAssignment.value.isValueInBraces) {
throw new IllegalStateException("value of object identifier \"" + valueAssignment.name + "\" is not defined in braces.");
}
List<Integer> oidComponents = new ArrayList<>();
List<String> tokens = valueAssignment.value.valueInBracesTokens;
for (int i = 0; i < tokens.size(); i++) {
String token = tokens.get(i);
if (Character.isDigit(token.charAt(0))) {
oidComponents.add(Integer.parseInt(token));
} else if (Character.isLetter(token.charAt(0))) {
if ((tokens.size() == i + 1) || !tokens.get(i + 1).equals("(")) {
// this is either a value reference of another object identifier or a registered name
if (!parseRegisteredOidComponentName(oidComponents, token)) {
BerObjectIdentifier oid = parseObjectIdentfierValue(token, module);
if (oid == null) {
for (SymbolsFromModule symbolsFromModule : module.importSymbolFromModuleList) {
for (String importedTypeName : symbolsFromModule.symbolList) {
if (token.equals(importedTypeName)) {
oid = parseObjectIdentfierValue(token, modulesByName.get(symbolsFromModule.modref));
}
}
}
}
if (oid == null) {
throw new IllegalStateException("AsnValueAssigment \"" + token + "\" was not found in module \"" + module.moduleIdentifier.name + "\"");
}
for (int element : oid.value) {
oidComponents.add(element);
}
}
}
}
}
return new BerObjectIdentifier(toIntArray(oidComponents));
}
Aggregations