java_gen: enable generation for all messages, lots of related fixes
diff --git a/java_gen/templates/_imports.java b/java_gen/templates/_imports.java
index bac7065..5b86571 100644
--- a/java_gen/templates/_imports.java
+++ b/java_gen/templates/_imports.java
@@ -7,6 +7,7 @@
 import org.openflow.protocol.instruction.*;
 import org.openflow.protocol.match.*;
 import org.openflow.protocol.oxm.*;
+import org.openflow.protocol.queueprop.*;
 import org.openflow.types.*;
 import org.openflow.types.*;
 import org.openflow.util.*;
diff --git a/java_gen/templates/of_class.java b/java_gen/templates/of_class.java
index 05018d3..0781dcf 100644
--- a/java_gen/templates/of_class.java
+++ b/java_gen/templates/of_class.java
@@ -129,26 +129,27 @@
     static class Reader implements OFMessageReader<${msg.interface.name}> {
         @Override
         public ${msg.interface.name} readFrom(ChannelBuffer bb) throws OFParseError {
+            int start = bb.readerIndex();
 //:: fields_with_length_member = {}
 //:: for prop in msg.members:
 //:: if prop.is_data:
-            ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version,
+            ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True,
                     length=fields_with_length_member[prop.c_name] if prop.c_name in fields_with_length_member else None)};
 //:: elif prop.is_pad:
             // pad: ${prop.length} bytes
             bb.skipBytes(${prop.length});
 //:: elif prop.is_fixed_value:
             // fixed value property ${prop.name} == ${prop.value}
-            ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version)};
-            if(${prop.name} != ${prop.value})
+            ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
+            if(${prop.name} != ${prop.priv_value})
                 throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
 //:: elif prop.is_length_value:
-            ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version)};
+            ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
             if(${prop.name} < MINIMUM_LENGTH)
                 throw new OFParseError("Wrong ${prop.name}: Expected to be >= " + MINIMUM_LENGTH + ", was: " + ${prop.name});
 //:: elif prop.is_field_length_value:
 //::        fields_with_length_member[prop.member.field_name] = prop.name
-            int ${prop.name} = ${prop.java_type.read_op(version)};
+            int ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
 //:: else:
     // fixme: todo ${prop.name}
 //:: #endif
@@ -173,32 +174,33 @@
     static class Writer implements OFMessageWriter<${impl_class}> {
         @Override
         public void write(ChannelBuffer bb, ${impl_class} message) {
-//:: if not msg.is_fixed_length:
             int startIndex = bb.writerIndex();
-//:: #end
-
 //:: fields_with_length_member = {}
 //:: for prop in msg.members:
 //:: if prop.c_name in fields_with_length_member:
             int ${prop.name}StartIndex = bb.writerIndex();
 //:: #endif
 //:: if prop.is_data:
-            ${prop.java_type.write_op(version, "message." + prop.name)};
+            ${prop.java_type.write_op(version, "message." + prop.name, pub_type=True)};
 //:: elif prop.is_pad:
             // pad: ${prop.length} bytes
             bb.writeZero(${prop.length});
 //:: elif prop.is_fixed_value:
             // fixed value property ${prop.name} = ${prop.value}
-            ${prop.java_type.write_op(version, prop.value)};
+            ${prop.java_type.write_op(version, prop.value, pub_type=False)};
 //:: elif prop.is_length_value:
             // ${prop.name} is length of variable message, will be updated at the end
+//:: if not msg.is_fixed_length:
+            int lengthIndex = bb.writerIndex();
+//:: #end
             ${prop.java_type.write_op(version, 0)};
+
 //:: elif prop.is_field_length_value:
 //::        fields_with_length_member[prop.member.field_name] = prop.name
             // ${prop.name} is length indicator for ${prop.member.field_name}, will be
             // udpated when ${prop.member.field_name} has been written
             int ${prop.name}Index = bb.writerIndex();
-            ${prop.java_type.write_op(version, 0)};
+            ${prop.java_type.write_op(version, 0, pub_type=False)};
 //:: else:
             // FIXME: todo write ${prop.name}
 //:: #endif
@@ -213,7 +215,7 @@
 //:: if not msg.is_fixed_length:
             // update length field
             int length = bb.writerIndex() - startIndex;
-            bb.setShort(startIndex + 2, length);
+            bb.setShort(lengthIndex, length);
             //:: if msg.align:
             // align message to ${msg.align} bytes
             bb.writeZero( ((length + ${msg.align-1})/${msg.align} * ${msg.align}) - length);
diff --git a/java_gen/templates/of_interface.java b/java_gen/templates/of_interface.java
index 186b787..4dec92f 100644
--- a/java_gen/templates/of_interface.java
+++ b/java_gen/templates/of_interface.java
@@ -51,6 +51,5 @@
         Builder set${prop.title_name}(${prop.java_type.public_type} ${prop.name})${ "" if prop.is_universal else " throws UnsupportedOperationException"};
 //:: #endif
 //:: #endfor
-
     }
 }
diff --git a/java_gen/templates/of_virtual_class.java b/java_gen/templates/of_virtual_class.java
new file mode 100644
index 0000000..f1ac849
--- /dev/null
+++ b/java_gen/templates/of_virtual_class.java
@@ -0,0 +1,102 @@
+//:: # 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.
+//::
+//:: from loxi_ir import *
+//:: import os
+//:: import itertools
+//:: import of_g
+//:: include('_copyright.java')
+
+//:: include('_autogen.java')
+
+package ${msg.package};
+
+//:: include("_imports.java", msg=msg)
+
+abstract class ${msg.name} implements ${msg.interface.name} {
+    // version: ${version}
+    private final static byte WIRE_VERSION = ${version.int_version};
+//:: if msg.is_fixed_length:
+    private final static int LENGTH = ${msg.length};
+//:: else:
+    private final static int MINIMUM_LENGTH = ${msg.min_length};
+//:: #endif
+
+
+    public final static ${msg.name}.Reader READER = new Reader();
+
+    static class Reader implements OFMessageReader<${msg.interface.name}> {
+        @Override
+        public ${msg.interface.name} readFrom(ChannelBuffer bb) throws OFParseError {
+            int start = bb.readerIndex();
+//:: fields_with_length_member = {}
+//::    for prop in msg.members:
+//::       if prop.is_data:
+            ${prop.java_type.skip_op(version,
+                    length=fields_with_length_member[prop.c_name] if prop.c_name in fields_with_length_member else None)};
+//:: elif prop.is_pad:
+            // pad: ${prop.length} bytes
+            bb.skipBytes(${prop.length});
+//:: elif prop.is_fixed_value:
+            // fixed value property ${prop.name} == ${prop.value}
+            ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
+            if(${prop.name} != ${prop.value})
+                throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
+//:: elif prop.is_length_value:
+            ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True)};
+            if(${prop.name} < MINIMUM_LENGTH)
+                throw new OFParseError("Wrong ${prop.name}: Expected to be >= " + MINIMUM_LENGTH + ", was: " + ${prop.name});
+//:: elif prop.is_field_length_value:
+//::        fields_with_length_member[prop.member.field_name] = prop.name
+            int ${prop.name} = ${prop.java_type.read_op(version)};
+//:: elif prop.is_discriminator:
+            ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
+            bb.readerIndex(start);
+            switch(${prop.name}) {
+//::     for sub in msg.subclasses:
+//::           if not model.generate_class(sub):
+               // skip ${sub.name} - excluded from generation
+//::           else:
+//::           m = sub.get_member(prop.name)
+//::           if not m.is_fixed_value:
+//::                  raise Exception("subtype %s of %s does not have fixed value for discriminator %s" %
+//::                           (sub.name, msg.name, prop.name))
+//::           #endif
+               case ${m.priv_value}:
+                   // discriminator value ${m.enum_value}=${m.value} for class ${sub.name}
+                   return ${sub.name}.READER.readFrom(bb);
+//:: #endif    # generate_class
+//:: #endfor
+               default:
+                   throw new OFParseError("Unknown value for discriminator ${prop.name} of class ${msg.name}: " + ${prop.name});
+            }
+//::        break
+//:: #endif
+//:: #endfor
+        }
+    }
+}
diff --git a/java_gen/templates/unit_test.java b/java_gen/templates/unit_test.java
index 1462465..45472f2 100644
--- a/java_gen/templates/unit_test.java
+++ b/java_gen/templates/unit_test.java
@@ -77,7 +77,7 @@
         // FIXME should invoke the overall reader once implemented
         ${var_type} ${var_name}Read = ${msg.name}.READER.readFrom(input);
 
-        assertEquals(${var_name}Read, ${var_name}Built);
+        assertEquals(${var_name}Built, ${var_name}Read);
    }
    //:: else:
    // FIXME: No java stanza in test_data for this class. Add for more comprehensive unit testing