Search in sources :

Example 1 with AsnParameter

use of com.beanit.asn1bean.compiler.model.AsnParameter 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 2 with AsnParameter

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

the class BerClassWriter method writeSequenceOrSetClass.

private void writeSequenceOrSetClass(String className, AsnSequenceSet asnSequenceSet, 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");
    List<AsnElementType> componentTypes = asnSequenceSet.componentTypes;
    addAutomaticTagsIfNeeded(componentTypes);
    if (asnSequenceSet.parameters != null) {
        List<AsnParameter> parameters = asnSequenceSet.parameters;
        replaceParametersByAnyTypes(componentTypes, parameters);
    }
    for (AsnElementType componentType : componentTypes) {
        if ((componentType.typeReference instanceof AsnConstructedType)) {
            listOfSubClassNames.add(getClassName(componentType));
        }
    }
    for (AsnElementType componentType : componentTypes) {
        if (isInnerType(componentType)) {
            String subClassName = getClassName(componentType, className);
            writeConstructedTypeClass(subClassName, componentType.typeReference, null, true, listOfSubClassNames);
        }
    }
    Tag mainTag;
    if (tag == null) {
        if (asnSequenceSet.isSequence) {
            mainTag = stdSeqTag;
        } else {
            mainTag = stdSetTag;
        }
    } else {
        mainTag = tag;
    }
    write("public static final BerTag tag = new BerTag(" + getBerTagParametersString(mainTag) + ");\n");
    write("private byte[] code = null;");
    setClassNamesOfComponents(listOfSubClassNames, componentTypes, className);
    writeMembers(componentTypes);
    if (asnSequenceSet.isSequence && accessExtended && extensibilityImplied) {
        String accessModifierString = jaxbMode ? "private" : "public";
        write(accessModifierString + " byte[] extensionBytes = null;");
    }
    writeEmptyConstructor(className);
    if (jaxbMode) {
        writeGetterAndSetter(componentTypes);
        if (asnSequenceSet.isSequence && accessExtended && extensibilityImplied) {
            write("public byte[] getExtensionBytes() {");
            write("return extensionBytes;");
            write("}\n");
            write("public void setExtensionBytes(byte[] bytes) {");
            write("this.extensionBytes = bytes;");
            write("}\n");
        }
    } else {
        writeEncodeConstructor(className, componentTypes);
    }
    boolean hasExplicitTag = (tag != null) && (tag.type == TagType.EXPLICIT);
    writeSimpleEncodeFunction();
    writeSequenceOrSetEncodeFunction(componentTypes, hasExplicitTag, asnSequenceSet.isSequence);
    writeSimpleDecodeFunction("true");
    if (asnSequenceSet.isSequence) {
        writeSequenceDecodeMethod(convertToComponentInfos(componentTypes), hasExplicitTag);
    } else {
        writeSetDecodeFunction(convertToComponentInfos(componentTypes), hasExplicitTag);
    }
    writeEncodeAndSaveFunction();
    writeSequenceOrSetToStringFunction(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) BerTag(com.beanit.asn1bean.ber.BerTag) AsnTag(com.beanit.asn1bean.compiler.model.AsnTag) AsnElementType(com.beanit.asn1bean.compiler.model.AsnElementType)

Example 3 with AsnParameter

use of com.beanit.asn1bean.compiler.model.AsnParameter 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)3 AsnParameter (com.beanit.asn1bean.compiler.model.AsnParameter)3 AsnBitString (com.beanit.asn1bean.compiler.model.AsnBitString)2 AsnCharacterString (com.beanit.asn1bean.compiler.model.AsnCharacterString)2 AsnConstructedType (com.beanit.asn1bean.compiler.model.AsnConstructedType)2 AsnOctetString (com.beanit.asn1bean.compiler.model.AsnOctetString)2 HexString (com.beanit.asn1bean.util.HexString)2 BerTag (com.beanit.asn1bean.ber.BerTag)1 AsnAny (com.beanit.asn1bean.compiler.model.AsnAny)1 AsnTag (com.beanit.asn1bean.compiler.model.AsnTag)1