use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.
the class BerClassWriter method writeChoiceToStringFunction.
private void writeChoiceToStringFunction(List<AsnElementType> componentTypes) throws IOException {
writeToStringFunction();
write("public void appendAsString(StringBuilder sb, int indentLevel) {\n");
for (AsnElementType componentType : componentTypes) {
write("if (" + getVariableName(componentType) + " != null) {");
if (!isPrimitive(getUniversalType(componentType))) {
write("sb.append(\"" + getVariableName(componentType) + ": \");");
write(getVariableName(componentType) + ".appendAsString(sb, indentLevel + 1);");
} else {
write("sb.append(\"" + getVariableName(componentType) + ": \").append(" + getVariableName(componentType) + ");");
}
write("return;");
write("}\n");
}
write("sb.append(\"<none>\");");
write("}\n");
}
use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.
the class BerClassWriter method writeSequenceOrSetEncodeFunction.
private void writeSequenceOrSetEncodeFunction(List<AsnElementType> componentTypes, boolean hasExplicitTag, boolean isSequence) throws IOException {
write("public int encode(OutputStream reverseOS, boolean withTag) throws IOException {\n");
writeEncodingIfCodeIsNull();
write("int codeLength = 0;");
for (int j = componentTypes.size() - 1; j >= 0; j--) {
if (isExplicit(getTag(componentTypes.get(j)))) {
write("int sublength;\n");
break;
}
}
if (isSequence && accessExtended && extensibilityImplied) {
write("if (extensionBytes != null) {");
write("reverseOS.write(extensionBytes);");
write("codeLength += extensionBytes.length;");
write("}\n");
}
for (int j = componentTypes.size() - 1; j >= 0; j--) {
AsnElementType componentType = componentTypes.get(j);
Tag componentTag = getTag(componentType);
if (isOptional(componentType)) {
write("if (" + getVariableName(componentType) + " != null) {");
}
String explicitEncoding = getExplicitEncodingParameter(componentType);
if (isExplicit(componentTag)) {
write("sublength = " + getVariableName(componentType) + ".encode(reverseOS" + explicitEncoding + ");");
write("codeLength += sublength;");
write("codeLength += BerLength.encodeLength(reverseOS, sublength);");
} else {
write("codeLength += " + getVariableName(componentType) + ".encode(reverseOS" + explicitEncoding + ");");
}
if (componentTag != null) {
writeEncodeTag(componentTag);
}
if (isOptional(componentType)) {
write("}");
}
write("");
}
if (hasExplicitTag) {
write("codeLength += BerLength.encodeLength(reverseOS, codeLength);");
if (isSequence) {
write("reverseOS.write(0x30);");
} else {
write("reverseOS.write(0x31);");
}
write("codeLength++;\n");
}
write("codeLength += BerLength.encodeLength(reverseOS, codeLength);\n");
write("if (withTag) {");
write("codeLength += tag.encode(reverseOS);");
write("}\n");
write("return codeLength;\n");
write("}\n");
}
use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.
the class BerClassWriter method writeMembers.
private void writeMembers(List<AsnElementType> componentTypes) throws IOException {
String accessModifierString = jaxbMode ? "private" : "public";
for (AsnElementType element : componentTypes) {
write(accessModifierString + " " + element.className + " " + cleanUpName(element.name) + " = null;");
}
write("");
}
use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.
the class BerClassWriter method replaceParametersByAnyTypes.
private void replaceParametersByAnyTypes(List<AsnElementType> componentTypes, List<AsnParameter> parameters) {
for (AsnParameter parameter : parameters) {
if (parameter.paramGovernor == null) {
for (AsnElementType componentType : componentTypes) {
if (componentType.definedType != null && componentType.definedType.typeName.equals(parameter.dummyReference)) {
componentType.typeReference = new AsnAny();
componentType.definedType = null;
componentType.isDefinedType = false;
}
}
}
}
}
use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.
the class BerClassWriter method writeSequenceOrSetToStringFunction.
private void writeSequenceOrSetToStringFunction(List<AsnElementType> componentTypes) throws IOException {
writeToStringFunction();
write("public void appendAsString(StringBuilder sb, int indentLevel) {\n");
write("sb.append(\"{\");");
boolean checkIfFirstSelectedElement = componentTypes.size() > 1;
int j = 0;
for (AsnElementType componentType : componentTypes) {
if (isOptional(componentType)) {
if (j == 0 && componentTypes.size() > 1) {
write("boolean firstSelectedElement = true;");
}
write("if (" + getVariableName(componentType) + " != null) {");
}
if (j != 0) {
if (checkIfFirstSelectedElement) {
write("if (!firstSelectedElement) {");
}
write("sb.append(\",\\n\");");
if (checkIfFirstSelectedElement) {
write("}");
}
} else {
write("sb.append(\"\\n\");");
}
write("for (int i = 0; i < indentLevel + 1; i++) {");
write("sb.append(\"\\t\");");
write("}");
if (!isOptional(componentType)) {
write("if (" + getVariableName(componentType) + " != null) {");
}
if (!isPrimitive(getUniversalType(componentType))) {
write("sb.append(\"" + getVariableName(componentType) + ": \");");
write(getVariableName(componentType) + ".appendAsString(sb, indentLevel + 1);");
} else {
write("sb.append(\"" + getVariableName(componentType) + ": \").append(" + getVariableName(componentType) + ");");
}
if (!isOptional(componentType)) {
write("}");
write("else {");
write("sb.append(\"" + getVariableName(componentType) + ": <empty-required-field>\");");
write("}");
}
if (isOptional(componentType)) {
if (checkIfFirstSelectedElement && j != (componentTypes.size() - 1)) {
write("firstSelectedElement = false;");
}
write("}");
} else {
checkIfFirstSelectedElement = false;
}
write("");
j++;
}
write("sb.append(\"\\n\");");
write("for (int i = 0; i < indentLevel; i++) {");
write("sb.append(\"\\t\");");
write("}");
write("sb.append(\"}\");");
write("}\n");
}
Aggregations