Search in sources :

Example 11 with AsnElementType

use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.

the class BerClassWriter method addAutomaticTagsIfNeeded.

private void addAutomaticTagsIfNeeded(List<AsnElementType> componentTypes) {
    if (tagDefault != TagDefault.AUTOMATIC) {
        return;
    }
    for (AsnElementType element : componentTypes) {
        if (getTag(element) != null) {
            return;
        }
    }
    int i = 0;
    for (AsnElementType element : componentTypes) {
        element.tag = new AsnTag();
        element.tag.classNumber = new AsnClassNumber();
        element.tag.classNumber.num = i;
        i++;
    }
}
Also used : AsnClassNumber(com.beanit.asn1bean.compiler.model.AsnClassNumber) AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType) AsnTag(com.beanit.asn1bean.compiler.model.AsnTag)

Example 12 with AsnElementType

use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.

the class BerClassWriter method writeGetterAndSetter.

private void writeGetterAndSetter(List<AsnElementType> componentTypes) throws IOException {
    for (AsnElementType element : componentTypes) {
        String typeName = getClassName(element);
        String getterName = cleanUpName("get" + capitalizeFirstCharacter(element.name));
        String setterName = cleanUpName("set" + capitalizeFirstCharacter(element.name));
        String variableName = cleanUpName(element.name);
        write("public void " + setterName + "(" + typeName + " " + variableName + ") {");
        write("this." + variableName + " = " + variableName + ";");
        write("}\n");
        write("public " + typeName + " " + getterName + "() {");
        write("return " + variableName + ";");
        write("}\n");
    }
}
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 13 with AsnElementType

use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.

the class BerClassWriter method writeSequenceOfClass.

private void writeSequenceOfClass(String className, AsnSequenceOf asnSequenceOf, Tag tag, String isStaticStr, List<String> listOfSubClassNames) throws IOException {
    write("public" + isStaticStr + " class " + className + " implements " + berTypeInterfaceString + "Serializable {\n");
    write("private static final long serialVersionUID = 1L;\n");
    AsnElementType componentType = asnSequenceOf.componentType;
    String referencedTypeName = getClassNameOfSequenceOfElement(componentType, listOfSubClassNames);
    if (isInnerType(componentType)) {
        writeConstructedTypeClass(referencedTypeName, componentType.typeReference, null, true, listOfSubClassNames);
    }
    Tag mainTag;
    if (tag == null) {
        if (asnSequenceOf.isSequenceOf) {
            mainTag = stdSeqTag;
        } else {
            mainTag = stdSetTag;
        }
    } else {
        mainTag = tag;
    }
    write("public static final BerTag tag = new BerTag(" + getBerTagParametersString(mainTag) + ");");
    write("private byte[] code = null;");
    if (jaxbMode) {
        write("private List<" + referencedTypeName + "> seqOf = null;\n");
    } else {
        write("public List<" + referencedTypeName + "> seqOf = null;\n");
    }
    write("public " + className + "() {");
    write("seqOf = new ArrayList<>();");
    write("}\n");
    write("public " + className + "(byte[] code) {");
    write("this.code = code;");
    write("}\n");
    if (!jaxbMode) {
        write("public " + className + "(List<" + referencedTypeName + "> seqOf) {");
        write("this.seqOf = seqOf;");
        write("}\n");
    }
    if (jaxbMode) {
        writeGetterForSeqOf(referencedTypeName);
    }
    boolean hasExplicitTag = (tag != null) && (tag.type == TagType.EXPLICIT);
    writeSimpleEncodeFunction();
    writeSequenceOfEncodeFunction(componentType, hasExplicitTag, asnSequenceOf.isSequenceOf);
    writeSimpleDecodeFunction("true");
    writeSequenceOrSetOfDecodeFunction(convertToComponentInfo(componentType, false, referencedTypeName), hasExplicitTag, asnSequenceOf.isSequenceOf);
    writeEncodeAndSaveFunction();
    writeSequenceOrSetOfToStringFunction(referencedTypeName, componentType);
    write("}\n");
}
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) BerTag(com.beanit.asn1bean.ber.BerTag) AsnTag(com.beanit.asn1bean.compiler.model.AsnTag) AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType)

Example 14 with AsnElementType

use of com.beanit.asn1bean.compiler.model.AsnElementType in project jasn1 by openmuc.

the class BerClassWriter method writeChoiceClass.

private void writeChoiceClass(String className, AsnChoice asn1TypeElement, Tag tag, String isStaticStr, List<String> listOfSubClassNames) throws IOException {
    write("public" + isStaticStr + " class " + className + " implements " + berTypeInterfaceString + "Serializable {\n");
    write("private static final long serialVersionUID = 1L;\n");
    write("private byte[] code = null;");
    if (tag != null) {
        write("public static final BerTag tag = new BerTag(" + getBerTagParametersString(tag) + ");\n");
    }
    List<AsnElementType> componentTypes = asn1TypeElement.componentTypes;
    addAutomaticTagsIfNeeded(componentTypes);
    if (asn1TypeElement.parameters != null) {
        List<AsnParameter> parameters = asn1TypeElement.parameters;
        replaceParametersByAnyTypes(componentTypes, parameters);
    }
    for (AsnElementType componentType : componentTypes) {
        if ((componentType.typeReference instanceof AsnConstructedType)) {
            listOfSubClassNames.add(getClassName(componentType, className));
        }
    }
    for (AsnElementType componentType : componentTypes) {
        if (isInnerType(componentType)) {
            String subClassName = getClassName(componentType, className);
            writeConstructedTypeClass(subClassName, componentType.typeReference, null, true, listOfSubClassNames);
        }
    }
    setClassNamesOfComponents(listOfSubClassNames, componentTypes, className);
    writeMembers(componentTypes);
    writeEmptyConstructor(className);
    if (!jaxbMode) {
        writeEncodeConstructor(className, componentTypes);
    }
    if (jaxbMode) {
        writeGetterAndSetter(componentTypes);
    }
    writeChoiceEncodeFunction(componentTypes, tag != null);
    writeChoiceDecodeMethod(convertToComponentInfos(componentTypes), tag != null);
    writeEncodeAndSaveFunction(tag == null);
    writeChoiceToStringFunction(componentTypes);
    write("}\n");
}
Also used : AsnConstructedType(com.beanit.asn1bean.compiler.model.AsnConstructedType) AsnParameter(com.beanit.asn1bean.compiler.model.AsnParameter) 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)

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