mil.dod.th.ose.jaxb.proto.converter/src/mil/dod/th/ose/jaxbprotoconverter/EnumConverterFileGenerator.java
public void genEnumConverterWrapperFile(final PrintStream outStream, final String className,
        final String packageName)
    {
        final DateFormat dateFormat = new SimpleDateFormat(GEN_DATE_FORMAT);
        final long currentDate = new Date().getTime();
        outStream.println(GEN_FILE_COMMENT + dateFormat.format(currentDate));
        outStream.format("package %s;%n%n", packageName);

        outStream.println("import com.google.protobuf.DescriptorProtos.FileOptions;");
        outStream.println("import com.google.protobuf.Descriptors.EnumValueDescriptor;");
        outStream.println("import com.google.protobuf.ProtocolMessageEnum;");
        outStream.println();

        // Import statements for enumeration converter classes
        for (EnumConverterInfo info : m_EnumConverters)
        {
            if (!packageName.equals(info.getEnumConverterPackageName()))
            {
                outStream.format("import %s.%s;%n", info.getEnumConverterPackageName(),
                    info.getEnumConverterClassName());
            }
        }

        outStream.println();

        // Class Definition
        outStream.format("public class %s {%n", className);

        // Method Definitions
        final String javaToProtoError = "String.format(\"Unknown java enum specified: %s\", javaValue)";
        final String protoToJavaError = "String.format(\"Unknown proto enum specified: %s\", protoValue)";
        final String protoDescToJavaError =
             "String.format(\"Unknown proto enum descriptor specified: %s\", protoValueDesc)";
        outStream.println("    public static ProtocolMessageEnum convertJavaEnumToProto(Enum<?> javaValue) {");
        outStream.println("        switch (javaValue.getClass().getName()) {");

        for (EnumConverterInfo info : m_EnumConverters)
        {
            outStream.format("            case \"%s\":%n", info.getJavaEnumName()); // NOCHECKSTYLE: Duplicate string is more readable
            outStream.format("                return %s.convertJavaEnumToProto((%s)javaValue);%n",
                info.getEnumConverterClassName(), info.getJavaEnumName());
        }

        outStream.println("            default:"); // NOCHECKSTYLE: Duplicate string is more readable
        outStream.format("                throw new IllegalArgumentException(%s);%n", javaToProtoError); // NOCHECKSTYLE: Duplicate string is more readable
        outStream.println("        }");
        outStream.println("    }");
        outStream.println();

        outStream.println("    public static Enum<?> convertProtoEnumToJava(ProtocolMessageEnum protoValue) {");
        outStream.println("        switch (protoValue.getClass().getName()) {");

        for (EnumConverterInfo info : m_EnumConverters)
        {
            outStream.format("            case \"%s\":%n", info.getProtoEnumName());
            outStream.format("                return %s.convertProtoEnumToJava((%s)protoValue);%n",
                info.getEnumConverterClassName(), info.getProtoEnumName());
        }

        outStream.println("            default:");
        outStream.format("                throw new IllegalArgumentException(%s);%n", protoToJavaError);
        outStream.println("        }");
        outStream.println("    }");
        outStream.println();

        outStream.println("    public static Enum<?> convertProtoEnumToJava(EnumValueDescriptor protoValueDesc) {");
        outStream.println("        FileOptions fileOptions = protoValueDesc.getFile().getOptions();");
        outStream.println("        String className = fileOptions.getJavaPackage()");
        outStream.println("            + \".\" + fileOptions.getJavaOuterClassname()");
        outStream.println("            + \".\" + protoValueDesc.getType().getContainingType().getName()");
        outStream.println("            + \".\" + protoValueDesc.getType().getName();");
        outStream.println();

        outStream.println("        switch (className) {");

        for (EnumConverterInfo info : m_EnumConverters)
        {
            outStream.format("            case \"%s\":%n", info.getProtoEnumName());
            outStream.format("                return %s.convertProtoEnumToJava(%s.valueOf(protoValueDesc));%n",
                info.getEnumConverterClassName(), info.getProtoEnumName());
        }

        outStream.println("            default:");
        outStream.format("                throw new IllegalArgumentException(%s);%n", protoDescToJavaError);
        outStream.println("        }");
        outStream.println("    }");

        outStream.println("}");
    }
/**
     * Generates an enumeration converter wrapper class that can be used to convert between Java and proto enumeration
     * values for all generated protocol buffer enumerations.
     * 
     * @param outStream
     *      source file output stream
     * @param className
     *      wrapper class name
     * @param packageName
     *      package name containing the wrapper class
     */
Generates an enumeration converter wrapper class that can be used to convert between Java and proto enumeration
values for all generated protocol buffer enumerations.

@param outStream
source file output stream
@param className
wrapper class name
@param packageName
package name containing the wrapper class
Generates an enumeration converter wrapper class that can be used to convert between Java and proto enumeration values for all generated protocol buffer enumerations . @param outStream source file output stream @param className wrapper class name @param packageName package name containing the wrapper class
public void genEnumConverterWrapperFile(final PrintStream outStream, final String className,
        final String packageName)
    {
        final DateFormat dateFormat = new SimpleDateFormat(GEN_DATE_FORMAT);
        final long currentDate = new Date().getTime();
        outStream.println(GEN_FILE_COMMENT + dateFormat.format(currentDate));
        outStream.format("package %s;%n%n", packageName);
        outStream.println("import com.google.protobuf.DescriptorProtos.FileOptions;");
        outStream.println("import com.google.protobuf.Descriptors.EnumValueDescriptor;");
        outStream.println("import com.google.protobuf.ProtocolMessageEnum;");
        outStream.println();
        for (EnumConverterInfo info : m_EnumConverters)
        {
            if (!packageName.equals(info.getEnumConverterPackageName()))
            {
                outStream.format("import %s.%s;%n", info.getEnumConverterPackageName(),
                    info.getEnumConverterClassName());
            }
        }
        outStream.println();
        outStream.format("public class %s {%n", className);
        final String javaToProtoError = "String.format(\"Unknown java enum specified: %s\", javaValue)";
        final String protoToJavaError = "String.format(\"Unknown proto enum specified: %s\", protoValue)";
        final String protoDescToJavaError =
             "String.format(\"Unknown proto enum descriptor specified: %s\", protoValueDesc)";
        outStream.println("    public static ProtocolMessageEnum convertJavaEnumToProto(Enum<?> javaValue) {");
        outStream.println("        switch (javaValue.getClass().getName()) {");
        for (EnumConverterInfo info : m_EnumConverters)
        {
            outStream.format("            case \"%s\":%n", info.getJavaEnumName()); 
            outStream.format("                return %s.convertJavaEnumToProto((%s)javaValue);%n",
                info.getEnumConverterClassName(), info.getJavaEnumName());
        }
        outStream.println("            default:"); 
        outStream.format("                throw new IllegalArgumentException(%s);%n", javaToProtoError); 
        outStream.println("        }");
        outStream.println("    }");
        outStream.println();
        outStream.println("    public static Enum<?> convertProtoEnumToJava(ProtocolMessageEnum protoValue) {");
        outStream.println("        switch (protoValue.getClass().getName()) {");
        for (EnumConverterInfo info : m_EnumConverters)
        {
            outStream.format("            case \"%s\":%n", info.getProtoEnumName());
            outStream.format("                return %s.convertProtoEnumToJava((%s)protoValue);%n",
                info.getEnumConverterClassName(), info.getProtoEnumName());
        }
        outStream.println("            default:");
        outStream.format("                throw new IllegalArgumentException(%s);%n", protoToJavaError);
        outStream.println("        }");
        outStream.println("    }");
        outStream.println();
        outStream.println("    public static Enum<?> convertProtoEnumToJava(EnumValueDescriptor protoValueDesc) {");
        outStream.println("        FileOptions fileOptions = protoValueDesc.getFile().getOptions();");
        outStream.println("        String className = fileOptions.getJavaPackage()");
        outStream.println("            + \".\" + fileOptions.getJavaOuterClassname()");
        outStream.println("            + \".\" + protoValueDesc.getType().getContainingType().getName()");
        outStream.println("            + \".\" + protoValueDesc.getType().getName();");
        outStream.println();
        outStream.println("        switch (className) {");
        for (EnumConverterInfo info : m_EnumConverters)
        {
            outStream.format("            case \"%s\":%n", info.getProtoEnumName());
            outStream.format("                return %s.convertProtoEnumToJava(%s.valueOf(protoValueDesc));%n",
                info.getEnumConverterClassName(), info.getProtoEnumName());
        }
        outStream.println("            default:");
        outStream.format("                throw new IllegalArgumentException(%s);%n", protoDescToJavaError);
        outStream.println("        }");
        outStream.println("    }");
        outStream.println("}");
    }
public void genEnumConverterWrapperFile ( final PrintStream outStream , final String className , final String packageName ) { final DateFormat dateFormat = new SimpleDateFormat ( GEN_DATE_FORMAT ) ; final long currentDate = new Date ( ) . getTime ( ) ; outStream . println ( GEN_FILE_COMMENT + dateFormat . format ( currentDate ) ) ; outStream . format ( "package %s;%n%n" , packageName ) ; outStream . println ( "import com.google.protobuf.DescriptorProtos.FileOptions;" ) ; outStream . println ( "import com.google.protobuf.Descriptors.EnumValueDescriptor;" ) ; outStream . println ( "import com.google.protobuf.ProtocolMessageEnum;" ) ; outStream . println ( ) ; for ( EnumConverterInfo info : m_EnumConverters ) { if ( ! packageName . equals ( info . getEnumConverterPackageName ( ) ) ) { outStream . format ( "import %s.%s;%n" , info . getEnumConverterPackageName ( ) , info . getEnumConverterClassName ( ) ) ; } } outStream . println ( ) ; outStream . format ( "public class %s {%n" , className ) ; final String javaToProtoError = "String.format(\"Unknown java enum specified: %s\", javaValue)" ; final String protoToJavaError = "String.format(\"Unknown proto enum specified: %s\", protoValue)" ; final String protoDescToJavaError = "String.format(\"Unknown proto enum descriptor specified: %s\", protoValueDesc)" ; outStream . println ( "    public static ProtocolMessageEnum convertJavaEnumToProto(Enum<?> javaValue) {" ) ; outStream . println ( "        switch (javaValue.getClass().getName()) {" ) ; for ( EnumConverterInfo info : m_EnumConverters ) { outStream . format ( "            case \"%s\":%n" , info . getJavaEnumName ( ) ) ; outStream . format ( "                return %s.convertJavaEnumToProto((%s)javaValue);%n" , info . getEnumConverterClassName ( ) , info . getJavaEnumName ( ) ) ; } outStream . println ( "            default:" ) ; outStream . format ( "                throw new IllegalArgumentException(%s);%n" , javaToProtoError ) ; outStream . println ( "        }" ) ; outStream . println ( "    }" ) ; outStream . println ( ) ; outStream . println ( "    public static Enum<?> convertProtoEnumToJava(ProtocolMessageEnum protoValue) {" ) ; outStream . println ( "        switch (protoValue.getClass().getName()) {" ) ; for ( EnumConverterInfo info : m_EnumConverters ) { outStream . format ( "            case \"%s\":%n" , info . getProtoEnumName ( ) ) ; outStream . format ( "                return %s.convertProtoEnumToJava((%s)protoValue);%n" , info . getEnumConverterClassName ( ) , info . getProtoEnumName ( ) ) ; } outStream . println ( "            default:" ) ; outStream . format ( "                throw new IllegalArgumentException(%s);%n" , protoToJavaError ) ; outStream . println ( "        }" ) ; outStream . println ( "    }" ) ; outStream . println ( ) ; outStream . println ( "    public static Enum<?> convertProtoEnumToJava(EnumValueDescriptor protoValueDesc) {" ) ; outStream . println ( "        FileOptions fileOptions = protoValueDesc.getFile().getOptions();" ) ; outStream . println ( "        String className = fileOptions.getJavaPackage()" ) ; outStream . println ( "            + \".\" + fileOptions.getJavaOuterClassname()" ) ; outStream . println ( "            + \".\" + protoValueDesc.getType().getContainingType().getName()" ) ; outStream . println ( "            + \".\" + protoValueDesc.getType().getName();" ) ; outStream . println ( ) ; outStream . println ( "        switch (className) {" ) ; for ( EnumConverterInfo info : m_EnumConverters ) { outStream . format ( "            case \"%s\":%n" , info . getProtoEnumName ( ) ) ; outStream . format ( "                return %s.convertProtoEnumToJava(%s.valueOf(protoValueDesc));%n" , info . getEnumConverterClassName ( ) , info . getProtoEnumName ( ) ) ; } outStream . println ( "            default:" ) ; outStream . format ( "                throw new IllegalArgumentException(%s);%n" , protoDescToJavaError ) ; outStream . println ( "        }" ) ; outStream . println ( "    }" ) ; outStream . println ( "}" ) ; }
Generates an enumeration converter wrapper class that can be used to convert between Java and proto enumeration
 values for all generated protocol buffer enumerations.
Generates an enumeration converter wrapper class that can be used to convert between Java and proto enumeration values for all generated protocol buffer enumerations .
// Import statements for enumeration converter classes // Class Definition // Method Definitions // NOCHECKSTYLE: Duplicate string is more readable // NOCHECKSTYLE: Duplicate string is more readable // NOCHECKSTYLE: Duplicate string is more readable