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++;
}
}
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");
}
}
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");
}
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");
}
Aggregations