Search in sources :

Example 1 with AsnElementType

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");
}
Also used : AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType)

Example 2 with AsnElementType

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");
}
Also used : BerTag(com.beanit.asn1bean.ber.BerTag) AsnTag(com.beanit.asn1bean.compiler.model.AsnTag) AsnCharacterString(com.beanit.asn1bean.compiler.model.AsnCharacterString) AsnOctetString(com.beanit.asn1bean.compiler.model.AsnOctetString) HexString(com.beanit.asn1bean.util.HexString) AsnBitString(com.beanit.asn1bean.compiler.model.AsnBitString) AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType)

Example 3 with AsnElementType

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("");
}
Also used : AsnCharacterString(com.beanit.asn1bean.compiler.model.AsnCharacterString) AsnOctetString(com.beanit.asn1bean.compiler.model.AsnOctetString) HexString(com.beanit.asn1bean.util.HexString) AsnBitString(com.beanit.asn1bean.compiler.model.AsnBitString) AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType)

Example 4 with AsnElementType

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;
                }
            }
        }
    }
}
Also used : AsnAny(com.beanit.asn1bean.compiler.model.AsnAny) AsnParameter(com.beanit.asn1bean.compiler.model.AsnParameter) AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType)

Example 5 with AsnElementType

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");
}
Also used : AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType)

Aggregations

AsnElementType (com.beanit.asn1bean.compiler.model.AsnElementType)14 AsnBitString (com.beanit.asn1bean.compiler.model.AsnBitString)9 AsnCharacterString (com.beanit.asn1bean.compiler.model.AsnCharacterString)9 AsnOctetString (com.beanit.asn1bean.compiler.model.AsnOctetString)9 HexString (com.beanit.asn1bean.util.HexString)9 AsnTag (com.beanit.asn1bean.compiler.model.AsnTag)5 BerTag (com.beanit.asn1bean.ber.BerTag)4 AsnParameter (com.beanit.asn1bean.compiler.model.AsnParameter)3 AsnConstructedType (com.beanit.asn1bean.compiler.model.AsnConstructedType)2 AsnAny (com.beanit.asn1bean.compiler.model.AsnAny)1 AsnClassNumber (com.beanit.asn1bean.compiler.model.AsnClassNumber)1 AsnSequenceSet (com.beanit.asn1bean.compiler.model.AsnSequenceSet)1 ArrayList (java.util.ArrayList)1