java_gen: support enum types, sets of enum types
diff --git a/java_gen/templates/const_set_serializer.java b/java_gen/templates/const_set_serializer.java
new file mode 100644
index 0000000..641b0c8
--- /dev/null
+++ b/java_gen/templates/const_set_serializer.java
@@ -0,0 +1,93 @@
+//:: # Copyright 2013, Big Switch Networks, Inc.
+//:: #
+//:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
+//:: # the following special exception:
+//:: #
+//:: # LOXI Exception
+//:: #
+//:: # As a special exception to the terms of the EPL, you may distribute libraries
+//:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
+//:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
+//:: # from the LoxiGen Libraries and the notice provided below is (i) included in
+//:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
+//:: # documentation for the LoxiGen Libraries, if distributed in binary form.
+//:: #
+//:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
+//:: #
+//:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
+//:: # a copy of the EPL at:
+//:: #
+//:: # http::: #www.eclipse.org/legal/epl-v10.html
+//:: #
+//:: # Unless required by applicable law or agreed to in writing, software
+//:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+//:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+//:: # EPL for the specific language governing permissions and limitations
+//:: # under the EPL.
+//::
+//:: import itertools
+//:: import of_g
+//:: include('_copyright.java')
+
+//:: include('_autogen.java')
+
+package ${package};
+
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+
+import org.projectfloodlight.openflow.types.*;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.projectfloodlight.openflow.exceptions.OFParseError;
+import org.projectfloodlight.openflow.protocol.OFVersion;
+import ${enum.package}.${enum.name};
+
+public class ${class_name} {
+    //:: wire_type = enum.wire_type(version)
+    //:: int_wire_type = enum.wire_type(version).pub_type
+    //:: entries = sorted([ (entry, entry.value(version)) for entry in enum.entries if entry.has_value(version) ], lambda (_,va), (_2,vb): va.__cmp__(vb))
+
+    //:: for entry, _ in entries:
+    public final static ${int_wire_type} ${entry.name}_VAL = ${entry.format_value(version)};
+    //:: #endfor
+
+    public static Set<${enum.name}> readFrom(ChannelBuffer bb) throws OFParseError {
+        try {
+            return ofWireValue(${wire_type.read_op(version)});
+        } catch (IllegalArgumentException e) {
+            throw new OFParseError(e);
+        }
+    }
+
+    public static void writeTo(ChannelBuffer bb, Set<${enum.name}> set) {
+        ${wire_type.write_op(version=version, name="toWireValue(set)")};
+    }
+
+    public static Set<${enum.name}> ofWireValue(${int_wire_type} val) {
+        EnumSet<${enum.name}> set = EnumSet.noneOf(${enum.name}.class);
+
+        //:: for entry, _ in entries:
+        if((val & ${entry.name}_VAL) != 0)
+            set.add(${enum.name}.${entry.name});
+        //:: #endfor
+        return Collections.unmodifiableSet(set);
+    }
+
+    public static ${int_wire_type} toWireValue(Set<${enum.name}> set) {
+        ${int_wire_type} wireValue = 0;
+
+        for(${enum.name} e: set) {
+            switch(e) {
+                //:: for entry, _ in entries:
+                case ${entry.name}:
+                    wireValue |= ${entry.name}_VAL;
+                //:: #endfor
+                default:
+                    throw new IllegalArgumentException("Illegal enum value for type ${enum.name} in version ${version}: " + e);
+            }
+        }
+        return wireValue;
+    }
+
+}