Search in sources :

Example 1 with AsnConstructedType

use of org.openmuc.jasn1.compiler.model.AsnConstructedType 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("public 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;
        replaceParamtersByAnyTypes(componentTypes, parameters);
    }
    for (AsnElementType componentType : componentTypes) {
        if (componentType.typeReference != null && (componentType.typeReference instanceof AsnConstructedType)) {
            listOfSubClassNames.add(getClassNameOfComponent(componentType));
        }
    }
    for (AsnElementType componentType : componentTypes) {
        if (isInnerType(componentType)) {
            String subClassName = getClassNameOfComponent(componentType);
            writeConstructedTypeClass(subClassName, componentType.typeReference, null, true, listOfSubClassNames);
        }
    }
    setClassNamesOfComponents(listOfSubClassNames, componentTypes);
    writePublicMembers(componentTypes);
    writeEmptyConstructor(className);
    if (!jaxbMode) {
        writeEncodeConstructor(className, componentTypes);
    }
    if (jaxbMode) {
        writeGetterAndSetter(componentTypes);
    }
    writeChoiceEncodeFunction(componentTypes, tag != null);
    writeChoiceDecodeFunction(componentTypes, tag != null);
    writeEncodeAndSaveFunction(tag == null);
    writeChoiceToStringFunction(componentTypes);
    write("}\n");
}
Also used : AsnConstructedType(org.openmuc.jasn1.compiler.model.AsnConstructedType) AsnParameter(org.openmuc.jasn1.compiler.model.AsnParameter) AsnBitString(org.openmuc.jasn1.compiler.model.AsnBitString) AsnCharacterString(org.openmuc.jasn1.compiler.model.AsnCharacterString) AsnOctetString(org.openmuc.jasn1.compiler.model.AsnOctetString) AsnElementType(org.openmuc.jasn1.compiler.model.AsnElementType)

Example 2 with AsnConstructedType

use of org.openmuc.jasn1.compiler.model.AsnConstructedType 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;
        replaceParamtersByAnyTypes(componentTypes, parameters);
    }
    for (AsnElementType componentType : componentTypes) {
        if (componentType.typeReference != null && (componentType.typeReference instanceof AsnConstructedType)) {
            listOfSubClassNames.add(getClassNameOfComponent(componentType));
        }
    }
    for (AsnElementType componentType : componentTypes) {
        if (isInnerType(componentType)) {
            String subClassName = getClassNameOfComponent(componentType);
            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("public byte[] code = null;");
    setClassNamesOfComponents(listOfSubClassNames, componentTypes);
    writePublicMembers(componentTypes);
    writeEmptyConstructor(className);
    if (!jaxbMode) {
        writeEncodeConstructor(className, componentTypes);
    }
    if (jaxbMode) {
        writeGetterAndSetter(componentTypes);
    }
    boolean hasExplicitTag = (tag != null) && (tag.type == TagType.EXPLICIT);
    writeSimpleEncodeFunction();
    writeSequenceOrSetEncodeFunction(componentTypes, hasExplicitTag, asnSequenceSet.isSequence);
    writeSimpleDecodeFunction("true");
    if (asnSequenceSet.isSequence) {
        writeSequenceDecodeFunction(componentTypes, hasExplicitTag);
    } else {
        writeSetDecodeFunction(componentTypes);
    }
    writeEncodeAndSaveFunction();
    writeSequenceOrSetToStringFunction(componentTypes);
    write("}\n");
}
Also used : AsnConstructedType(org.openmuc.jasn1.compiler.model.AsnConstructedType) AsnParameter(org.openmuc.jasn1.compiler.model.AsnParameter) AsnBitString(org.openmuc.jasn1.compiler.model.AsnBitString) AsnCharacterString(org.openmuc.jasn1.compiler.model.AsnCharacterString) AsnOctetString(org.openmuc.jasn1.compiler.model.AsnOctetString) BerTag(org.openmuc.jasn1.ber.BerTag) AsnTag(org.openmuc.jasn1.compiler.model.AsnTag) AsnElementType(org.openmuc.jasn1.compiler.model.AsnElementType)

Example 3 with AsnConstructedType

use of org.openmuc.jasn1.compiler.model.AsnConstructedType in project jasn1 by openmuc.

the class BerClassWriter method getConstructorParametersFromConstructedElement.

private String[] getConstructorParametersFromConstructedElement(AsnConstructedType assignedTypeDefinition) throws IOException {
    List<AsnElementType> componentTypes;
    if (assignedTypeDefinition instanceof AsnSequenceSet) {
        componentTypes = ((AsnSequenceSet) assignedTypeDefinition).componentTypes;
    } else {
        componentTypes = ((AsnChoice) assignedTypeDefinition).componentTypes;
    }
    String[] constructorParameters = new String[componentTypes.size() * 2];
    for (int j = 0; j < componentTypes.size(); j++) {
        AsnElementType componentType = componentTypes.get(j);
        constructorParameters[j * 2] = getClassNameOfComponent(componentType);
        constructorParameters[j * 2 + 1] = cleanUpName(componentType.name);
    }
    return constructorParameters;
}
Also used : AsnBitString(org.openmuc.jasn1.compiler.model.AsnBitString) AsnCharacterString(org.openmuc.jasn1.compiler.model.AsnCharacterString) AsnOctetString(org.openmuc.jasn1.compiler.model.AsnOctetString) AsnElementType(org.openmuc.jasn1.compiler.model.AsnElementType) AsnSequenceSet(org.openmuc.jasn1.compiler.model.AsnSequenceSet)

Example 4 with AsnConstructedType

use of org.openmuc.jasn1.compiler.model.AsnConstructedType in project jasn1 by openmuc.

the class BerClassWriter method translateModule.

public void translateModule(AsnModule module) throws IOException {
    System.out.println("Generating classes for module \"" + module.moduleIdentifier.name + "\"");
    outputDirectory = new File(outputBaseDir, sanitizeModuleName(module.moduleIdentifier.name).replace('-', '/').toLowerCase());
    this.module = module;
    tagDefault = module.tagDefault;
    for (AsnType typeDefinition : module.typesByName.values()) {
        if (typeDefinition instanceof AsnDefinedType) {
            if (getInformationObjectClass(((AsnDefinedType) typeDefinition).typeName, module) != null) {
                continue;
            }
        }
        String typeName = cleanUpName(typeDefinition.name);
        writeClassHeader(typeName, module);
        if (typeDefinition instanceof AsnTaggedType) {
            AsnTaggedType asnTaggedType = (AsnTaggedType) typeDefinition;
            Tag tag = getTag(asnTaggedType);
            if (asnTaggedType.definedType != null) {
                writeRetaggingTypeClass(typeName, asnTaggedType.definedType.typeName, typeDefinition, tag);
            } else {
                AsnType assignedAsnType = asnTaggedType.typeReference;
                if (assignedAsnType instanceof AsnConstructedType) {
                    writeConstructedTypeClass(typeName, assignedAsnType, tag, false, null);
                } else {
                    writeRetaggingTypeClass(typeName, getBerType(assignedAsnType), typeDefinition, tag);
                }
            }
        } else if (typeDefinition instanceof AsnDefinedType) {
            writeRetaggingTypeClass(typeName, ((AsnDefinedType) typeDefinition).typeName, typeDefinition, null);
        } else if (typeDefinition instanceof AsnConstructedType) {
            writeConstructedTypeClass(typeName, typeDefinition, null, false, null);
        } else {
            writeRetaggingTypeClass(typeName, getBerType(typeDefinition), typeDefinition, null);
        }
        out.close();
    }
    writeOidValues(module);
}
Also used : AsnTaggedType(org.openmuc.jasn1.compiler.model.AsnTaggedType) AsnConstructedType(org.openmuc.jasn1.compiler.model.AsnConstructedType) AsnBitString(org.openmuc.jasn1.compiler.model.AsnBitString) AsnCharacterString(org.openmuc.jasn1.compiler.model.AsnCharacterString) AsnOctetString(org.openmuc.jasn1.compiler.model.AsnOctetString) BerTag(org.openmuc.jasn1.ber.BerTag) AsnTag(org.openmuc.jasn1.compiler.model.AsnTag) File(java.io.File) AsnDefinedType(org.openmuc.jasn1.compiler.model.AsnDefinedType) AsnType(org.openmuc.jasn1.compiler.model.AsnType)

Aggregations

AsnBitString (org.openmuc.jasn1.compiler.model.AsnBitString)4 AsnCharacterString (org.openmuc.jasn1.compiler.model.AsnCharacterString)4 AsnOctetString (org.openmuc.jasn1.compiler.model.AsnOctetString)4 AsnConstructedType (org.openmuc.jasn1.compiler.model.AsnConstructedType)3 AsnElementType (org.openmuc.jasn1.compiler.model.AsnElementType)3 BerTag (org.openmuc.jasn1.ber.BerTag)2 AsnParameter (org.openmuc.jasn1.compiler.model.AsnParameter)2 AsnTag (org.openmuc.jasn1.compiler.model.AsnTag)2 File (java.io.File)1 AsnDefinedType (org.openmuc.jasn1.compiler.model.AsnDefinedType)1 AsnSequenceSet (org.openmuc.jasn1.compiler.model.AsnSequenceSet)1 AsnTaggedType (org.openmuc.jasn1.compiler.model.AsnTaggedType)1 AsnType (org.openmuc.jasn1.compiler.model.AsnType)1