Example #1
0
 public JavaClass createClass(String name, Type type, boolean constructed)
     throws CompilerException {
   JavaClass javaClass =
       new JavaClass(
           pkg,
           name,
           type.getTag(),
           CompilerUtils.getTaggingMode(getModule(), type),
           true,
           runtimeTypes.get(type.getClass().getSimpleName()));
   currentClass.push(javaClass);
   return javaClass;
 }
Example #2
0
  public String getType(JavaClass javaClass, Type type) throws CompilerException {
    String typeName;
    String name = null;
    boolean newType = false;

    if (type instanceof NamedType) {
      name = ((NamedType) type).getName();
      type = ((NamedType) type).getType();
    }

    if (type instanceof TypeReference) {
      if (type instanceof UsefulType) {
        typeName = ((UsefulType) type).getType();
      } else {
        String asn1TypeName = ((TypeReference) type).getType();
        addReferencedType(asn1TypeName);
        typeName = CompilerUtils.formatName(asn1TypeName);
      }
    } else if (type instanceof BooleanType) {
      typeName = ch.eskaton.asn4j.runtime.types.ASN1Boolean.class.getSimpleName();
    } else if (type instanceof VisibleString) {
      typeName = ch.eskaton.asn4j.runtime.types.ASN1VisibleString.class.getSimpleName();
    } else if (type instanceof OctetString) {
      typeName = ch.eskaton.asn4j.runtime.types.ASN1OctetString.class.getSimpleName();
    } else if (type instanceof IntegerType) {
      if (((IntegerType) type).getNamedNumbers() != null && name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1Integer.class.getSimpleName();
      }
    } else if (type instanceof BitString) {
      if (((BitString) type).getNamedBits() != null && name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1BitString.class.getSimpleName();
      }
    } else if (type instanceof SequenceOfType) {
      if (name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1SequenceOf.class.getSimpleName();
      }
    } else if (type instanceof SetType) {
      if (name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1Set.class.getSimpleName();
      }
    } else if (type instanceof SequenceType) {
      if (name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1Sequence.class.getSimpleName();
      }
    } else if (type instanceof Choice) {
      typeName = CompilerUtils.formatTypeName(name);
      newType = true;
    } else {
      throw new CompilerException("Unsupported type: " + type.getClass());
    }

    if (newType) {
      this.<Type, TypeCompiler>getCompiler(Type.class).compile(this, typeName, type);
      definedTypes.add(name);
    }

    return typeName;
  }