activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [32/51] [partial] https://issues.apache.org/jira/browse/OPENWIRE-1
Date Thu, 24 Jul 2014 14:23:21 GMT
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MarshallingGenerator.java
----------------------------------------------------------------------
diff --git a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MarshallingGenerator.java b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MarshallingGenerator.java
new file mode 100644
index 0000000..b03c603
--- /dev/null
+++ b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MarshallingGenerator.java
@@ -0,0 +1,712 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.generator;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JAnnotationValue;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JPackage;
+import org.codehaus.jam.JProperty;
+
+/**
+ * Generates the binary marshalers for the OpenWire commands.
+ */
+public class MarshallingGenerator extends MultiSourceGenerator {
+
+    protected List<JClass> concreteClasses = new ArrayList<JClass>();
+    protected File factoryFile;
+    protected String factoryFileName = "MarshallerFactory";
+    protected String indent = "    ";
+
+    private final String packagePrefixPath = codecPackageRoot.replace('.', '/');
+
+    public MarshallingGenerator() {
+        this.targetDir = "src/main/java";
+    }
+
+    @Override
+    public Object run() {
+        if (destDir == null) {
+            destDir = new File(getTargetDir() + "/" + packagePrefixPath + "/v" + getOpenwireVersion());
+        }
+        Object answer = super.run();
+        //processFactory();
+        return answer;
+    }
+
+    @Override
+    protected void generateFile(PrintWriter out) throws Exception {
+
+        generateLicence(out);
+        out.println("");
+        out.println("package " + getCodecPackageRoot() + ".v" + getOpenwireVersion() + ";");
+        out.println("");
+        out.println("import java.io.DataInput;");
+        out.println("import java.io.DataOutput;");
+        out.println("import java.io.IOException;");
+        out.println("");
+        out.println("import " + getCodecPackageRoot() + ".*;");
+        out.println("import " + getCommandsPackage() + ".*;");
+        out.println("");
+
+        for (JPackage pkg : getJclass().getImportedPackages()) {
+            for (JClass clazz : pkg.getClasses()) {
+                out.println("import " + clazz.getQualifiedName() + ";");
+            }
+        }
+
+        out.println("");
+        out.println("/**");
+        out.println(" * Marshalling code for Open Wire for " + getClassName() + "");
+        out.println(" *");
+        out.println(" * NOTE!: This file is auto generated - do not modify!");
+        out.println(" *");
+        out.println(" */");
+        out.println("public " + getAbstractClassText() + "class " + getClassName() + " extends " + getBaseClass() + " {");
+        out.println("");
+
+        if (!isAbstractClass()) {
+
+            out.println("    /**");
+            out.println("     * Return the type of Data Structure we marshal");
+            out.println("     * @return short representation of the type data structure");
+            out.println("     */");
+            out.println("    public byte getDataStructureType() {");
+            out.println("        return " + getJclass().getSimpleName() + ".DATA_STRUCTURE_TYPE;");
+            out.println("    }");
+            out.println("    ");
+            out.println("    /**");
+            out.println("     * @return a new object instance");
+            out.println("     */");
+            out.println("    public DataStructure createObject() {");
+            out.println("        return new " + getJclass().getSimpleName() + "();");
+            out.println("    }");
+            out.println("");
+        }
+
+        out.println("    /**");
+        out.println("     * Un-marshal an object instance from the data input stream");
+        out.println("     *");
+        out.println("     * @param o the object to un-marshal");
+        out.println("     * @param dataIn the data input stream to build the object from");
+        out.println("     * @throws IOException");
+        out.println("     */");
+        out.println("    public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException {");
+        out.println("        super.tightUnmarshal(wireFormat, o, dataIn, bs);");
+
+        if (!getProperties().isEmpty()) {
+            out.println("");
+            out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
+        }
+
+        if (isMarshallerAware()) {
+            out.println("");
+            out.println("        info.beforeUnmarshall(wireFormat);");
+            out.println("        ");
+        }
+
+        generateTightUnmarshalBody(out);
+
+        if (isMarshallerAware()) {
+            out.println("");
+            out.println("        info.afterUnmarshall(wireFormat);");
+        }
+
+        out.println("");
+        out.println("    }");
+        out.println("");
+        out.println("");
+        out.println("    /**");
+        out.println("     * Write the booleans that this object uses to a BooleanStream");
+        out.println("     */");
+        out.println("    public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException {");
+
+        if (!getProperties().isEmpty()) {
+            out.println("");
+            out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
+        }
+
+        if (isMarshallerAware()) {
+            out.println("");
+            out.println("        info.beforeMarshall(wireFormat);");
+        }
+
+        out.println("");
+        out.println("        int rc = super.tightMarshal1(wireFormat, o, bs);");
+        int baseSize = generateTightMarshal1Body(out);
+
+        out.println("");
+        out.println("        return rc + " + baseSize + ";");
+        out.println("    }");
+        out.println("");
+        out.println("    /**");
+        out.println("     * Write a object instance to data output stream");
+        out.println("     *");
+        out.println("     * @param o the instance to be marshaled");
+        out.println("     * @param dataOut the output stream");
+        out.println("     * @throws IOException thrown if an error occurs");
+        out.println("     */");
+        out.println("    public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs) throws IOException {");
+        out.println("        super.tightMarshal2(wireFormat, o, dataOut, bs);");
+        if (!getProperties().isEmpty()) {
+            out.println("");
+            out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
+        }
+
+        generateTightMarshal2Body(out);
+
+        if (isMarshallerAware()) {
+            out.println("");
+            out.println("        info.afterMarshall(wireFormat);");
+        }
+
+        out.println("");
+        out.println("    }");
+        out.println("");
+        out.println("    /**");
+        out.println("     * Un-marshal an object instance from the data input stream");
+        out.println("     *");
+        out.println("     * @param o the object to un-marshal");
+        out.println("     * @param dataIn the data input stream to build the object from");
+        out.println("     * @throws IOException");
+        out.println("     */");
+        out.println("    public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException {");
+        out.println("        super.looseUnmarshal(wireFormat, o, dataIn);");
+
+        if (!getProperties().isEmpty()) {
+            out.println("");
+            out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
+        }
+
+        if (isMarshallerAware()) {
+            out.println("");
+            out.println("        info.beforeUnmarshall(wireFormat);");
+            out.println("        ");
+        }
+
+        generateLooseUnmarshalBody(out);
+
+        if (isMarshallerAware()) {
+            out.println("");
+            out.println("        info.afterUnmarshall(wireFormat);");
+        }
+
+        out.println("");
+        out.println("    }");
+        out.println("");
+        out.println("");
+        out.println("    /**");
+        out.println("     * Write the booleans that this object uses to a BooleanStream");
+        out.println("     */");
+        out.println("    public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException {");
+
+        if (!getProperties().isEmpty()) {
+            out.println("");
+            out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
+        }
+
+        if (isMarshallerAware()) {
+            out.println("");
+            out.println("        info.beforeMarshall(wireFormat);");
+        }
+
+        out.println("");
+        out.println("        super.looseMarshal(wireFormat, o, dataOut);");
+
+        generateLooseMarshalBody(out);
+
+        out.println("");
+        out.println("    }");
+        out.println("}");
+    }
+
+    private void generateLicence(PrintWriter out) {
+        out.println("/**");
+        out.println(" *");
+        out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+        out.println(" * contributor license agreements.  See the NOTICE file distributed with");
+        out.println(" * this work for additional information regarding copyright ownership.");
+        out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+        out.println(" * (the \"License\"); you may not use this file except in compliance with");
+        out.println(" * the License.  You may obtain a copy of the License at");
+        out.println(" *");
+        out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+        out.println(" *");
+        out.println(" * Unless required by applicable law or agreed to in writing, software");
+        out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+        out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+        out.println(" * See the License for the specific language governing permissions and");
+        out.println(" * limitations under the License.");
+        out.println(" */");
+    }
+
+    protected void processFactory() {
+        if (factoryFile == null) {
+            factoryFile = new File(destDir, factoryFileName + filePostFix);
+        }
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileWriter(factoryFile));
+            generateFactory(out);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (out != null) {
+                out.close();
+            }
+        }
+    }
+
+    protected void generateFactory(PrintWriter out) {
+        generateLicence(out);
+        out.println("");
+        out.println("package " + getCodecPackageRoot() + ".v" + getOpenwireVersion() + ";");
+        out.println("");
+        out.println("import " + getCodecPackageRoot() + ".DataStreamMarshaller;");
+        out.println("import " + getCodecPackageRoot() + ".OpenWireFormat;");
+        out.println("");
+        out.println("/**");
+        out.println(" * MarshallerFactory for Open Wire Format.");
+        out.println(" *");
+        out.println(" *");
+        out.println(" * NOTE!: This file is auto generated - do not modify!");
+        out.println(" * ");
+        out.println(" */");
+        out.println("public class MarshallerFactory {");
+        out.println("");
+        out.println("    /**");
+        out.println("     * Creates a Map of command type -> Marshallers");
+        out.println("     */");
+        out.println("    static final private DataStreamMarshaller marshaller[] = new DataStreamMarshaller[256];");
+        out.println("    static {");
+        out.println("");
+
+        List<JClass> list = new ArrayList<JClass>(getConcreteClasses());
+        Collections.sort(list, new Comparator<JClass>() {
+            @Override
+            public int compare(JClass o1, JClass o2) {
+                return o1.getSimpleName().compareTo(o2.getSimpleName());
+            }
+        });
+
+        for (Iterator<JClass> iter = list.iterator(); iter.hasNext();) {
+            JClass jclass = iter.next();
+            out.println("        add(new " + jclass.getSimpleName() + "Marshaller());");
+        }
+
+        out.println("");
+        out.println("    }");
+        out.println("");
+        out.println("    static private void add(DataStreamMarshaller dsm) {");
+        out.println("        marshaller[dsm.getDataStructureType()] = dsm;");
+        out.println("    }");
+        out.println("    ");
+        out.println("    static public DataStreamMarshaller[] createMarshallerMap(OpenWireFormat wireFormat) {");
+        out.println("        return marshaller;");
+        out.println("    }");
+        out.println("}");
+    }
+
+    @Override
+    protected void processClass(JClass jclass) {
+        super.processClass(jclass);
+
+        if (!jclass.isAbstract()) {
+            concreteClasses.add(jclass);
+        }
+    }
+
+    @Override
+    protected String getClassName(JClass jclass) {
+        return super.getClassName(jclass) + "Marshaller";
+    }
+
+    @Override
+    protected String getBaseClassName(JClass jclass) {
+        String answer = "BaseDataStreamMarshaller";
+        JClass superclass = jclass.getSuperclass();
+        if (superclass != null) {
+            String superName = superclass.getSimpleName();
+            if (!superName.equals("Object") && !superName.equals("JNDIBaseStorable") && !superName.equals("DataStructureSupport")) {
+                answer = superName + "Marshaller";
+            }
+        }
+        return answer;
+    }
+
+    @Override
+    protected void initialiseManuallyMaintainedClasses() {
+    }
+
+    protected void generateTightUnmarshalBody(PrintWriter out) {
+        for (JProperty property : getProperties()) {
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String propertyTypeName = propertyType.getSimpleName();
+
+            if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
+                generateTightUnmarshalBodyForArrayProperty(out, property, size);
+            } else {
+                generateTightUnmarshalBodyForProperty(out, property, size);
+            }
+        }
+    }
+
+    protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+        String setter = property.getSetter().getSimpleName();
+        String type = property.getType().getSimpleName();
+
+        if (type.equals("boolean")) {
+            out.println("        info." + setter + "(bs.readBoolean());");
+        } else if (type.equals("byte")) {
+            out.println("        info." + setter + "(dataIn.readByte());");
+        } else if (type.equals("char")) {
+            out.println("        info." + setter + "(dataIn.readChar());");
+        } else if (type.equals("short")) {
+            out.println("        info." + setter + "(dataIn.readShort());");
+        } else if (type.equals("int")) {
+            out.println("        info." + setter + "(dataIn.readInt());");
+        } else if (type.equals("long")) {
+            out.println("        info." + setter + "(tightUnmarshalLong(wireFormat, dataIn, bs));");
+        } else if (type.equals("String")) {
+            out.println("        info." + setter + "(tightUnmarshalString(dataIn, bs));");
+        } else if (type.equals("byte[]")) {
+            if (size != null) {
+                out.println("        info." + setter + "(tightUnmarshalConstByteArray(dataIn, bs, " + size.asInt() + "));");
+            } else {
+                out.println("        info." + setter + "(tightUnmarshalByteArray(dataIn, bs));");
+            }
+        } else if (type.equals("ByteSequence")) {
+            out.println("        info." + setter + "(tightUnmarshalByteSequence(dataIn, bs));");
+        } else if (isThrowable(property.getType())) {
+            out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalThrowable(wireFormat, dataIn, bs));");
+        } else if (isCachedProperty(property)) {
+            out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalCachedObject(wireFormat, dataIn, bs));");
+        } else {
+            out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalNestedObject(wireFormat, dataIn, bs));");
+        }
+    }
+
+    protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+        JClass propertyType = property.getType();
+        String arrayType = propertyType.getArrayComponentType().getQualifiedName();
+        String setter = property.getSetter().getSimpleName();
+        out.println();
+        if (size != null) {
+            out.println("        {");
+            out.println("            " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
+            out.println("            " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
+            out.println("            }");
+            out.println("            info." + setter + "(value);");
+            out.println("        }");
+        } else {
+            out.println("        if (bs.readBoolean()) {");
+            out.println("            short size = dataIn.readShort();");
+            out.println("            " + arrayType + " value[] = new " + arrayType + "[size];");
+            out.println("            for( int i=0; i < size; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
+            out.println("            }");
+            out.println("            info." + setter + "(value);");
+            out.println("        }");
+            out.println("        else {");
+            out.println("            info." + setter + "(null);");
+            out.println("        }");
+        }
+    }
+
+    protected int generateTightMarshal1Body(PrintWriter out) {
+        int baseSize = 0;
+        for (JProperty property : getProperties()) {
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String type = propertyType.getSimpleName();
+            String getter = "info." + property.getGetter().getSimpleName() + "()";
+
+            if (type.equals("boolean")) {
+                out.println("        bs.writeBoolean(" + getter + ");");
+            } else if (type.equals("byte")) {
+                baseSize += 1;
+            } else if (type.equals("char")) {
+                baseSize += 2;
+            } else if (type.equals("short")) {
+                baseSize += 2;
+            } else if (type.equals("int")) {
+                baseSize += 4;
+            } else if (type.equals("long")) {
+                out.println("        rc+=tightMarshalLong1(wireFormat, " + getter + ", bs);");
+            } else if (type.equals("String")) {
+                out.println("        rc += tightMarshalString1(" + getter + ", bs);");
+            } else if (type.equals("byte[]")) {
+                if (size == null) {
+                    out.println("        rc += tightMarshalByteArray1(" + getter + ", bs);");
+                } else {
+                    out.println("        rc += tightMarshalConstByteArray1(" + getter + ", bs, " + size.asInt() + ");");
+                }
+            } else if (type.equals("ByteSequence")) {
+                out.println("        rc += tightMarshalByteSequence1(" + getter + ", bs);");
+            } else if (propertyType.isArrayType()) {
+                if (size != null) {
+                    out.println("        rc += tightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
+                } else {
+                    out.println("        rc += tightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
+                }
+            } else if (isThrowable(propertyType)) {
+                out.println("        rc += tightMarshalThrowable1(wireFormat, " + getter + ", bs);");
+            } else {
+                if (isCachedProperty(property)) {
+                    out.println("        rc += tightMarshalCachedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
+                } else {
+                    out.println("        rc += tightMarshalNestedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
+                }
+            }
+        }
+        return baseSize;
+    }
+
+    protected void generateTightMarshal2Body(PrintWriter out) {
+        for (JProperty property : getProperties()) {
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String type = propertyType.getSimpleName();
+            String getter = "info." + property.getGetter().getSimpleName() + "()";
+
+            if (type.equals("boolean")) {
+                out.println("        bs.readBoolean();");
+            } else if (type.equals("byte")) {
+                out.println("        dataOut.writeByte(" + getter + ");");
+            } else if (type.equals("char")) {
+                out.println("        dataOut.writeChar(" + getter + ");");
+            } else if (type.equals("short")) {
+                out.println("        dataOut.writeShort(" + getter + ");");
+            } else if (type.equals("int")) {
+                out.println("        dataOut.writeInt(" + getter + ");");
+            } else if (type.equals("long")) {
+                out.println("        tightMarshalLong2(wireFormat, " + getter + ", dataOut, bs);");
+            } else if (type.equals("String")) {
+                out.println("        tightMarshalString2(" + getter + ", dataOut, bs);");
+            } else if (type.equals("byte[]")) {
+                if (size != null) {
+                    out.println("        tightMarshalConstByteArray2(" + getter + ", dataOut, bs, " + size.asInt() + ");");
+                } else {
+                    out.println("        tightMarshalByteArray2(" + getter + ", dataOut, bs);");
+                }
+            } else if (type.equals("ByteSequence")) {
+                out.println("        tightMarshalByteSequence2(" + getter + ", dataOut, bs);");
+            } else if (propertyType.isArrayType()) {
+                if (size != null) {
+                    out.println("        tightMarshalObjectArrayConstSize2(wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + ");");
+                } else {
+                    out.println("        tightMarshalObjectArray2(wireFormat, " + getter + ", dataOut, bs);");
+                }
+            } else if (isThrowable(propertyType)) {
+                out.println("        tightMarshalThrowable2(wireFormat, " + getter + ", dataOut, bs);");
+            } else {
+                if (isCachedProperty(property)) {
+                    out.println("        tightMarshalCachedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
+                } else {
+                    out.println("        tightMarshalNestedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
+                }
+            }
+        }
+    }
+
+    protected void generateLooseMarshalBody(PrintWriter out) {
+        for (JProperty property : getProperties()) {
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String type = propertyType.getSimpleName();
+            String getter = "info." + property.getGetter().getSimpleName() + "()";
+
+            if (type.equals("boolean")) {
+                out.println("        dataOut.writeBoolean(" + getter + ");");
+            } else if (type.equals("byte")) {
+                out.println("        dataOut.writeByte(" + getter + ");");
+            } else if (type.equals("char")) {
+                out.println("        dataOut.writeChar(" + getter + ");");
+            } else if (type.equals("short")) {
+                out.println("        dataOut.writeShort(" + getter + ");");
+            } else if (type.equals("int")) {
+                out.println("        dataOut.writeInt(" + getter + ");");
+            } else if (type.equals("long")) {
+                out.println("        looseMarshalLong(wireFormat, " + getter + ", dataOut);");
+            } else if (type.equals("String")) {
+                out.println("        looseMarshalString(" + getter + ", dataOut);");
+            } else if (type.equals("byte[]")) {
+                if (size != null) {
+                    out.println("        looseMarshalConstByteArray(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
+                } else {
+                    out.println("        looseMarshalByteArray(wireFormat, " + getter + ", dataOut);");
+                }
+            } else if (type.equals("ByteSequence")) {
+                out.println("        looseMarshalByteSequence(wireFormat, " + getter + ", dataOut);");
+            } else if (propertyType.isArrayType()) {
+                if (size != null) {
+                    out.println("        looseMarshalObjectArrayConstSize(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
+                } else {
+                    out.println("        looseMarshalObjectArray(wireFormat, " + getter + ", dataOut);");
+                }
+            } else if (isThrowable(propertyType)) {
+                out.println("        looseMarshalThrowable(wireFormat, " + getter + ", dataOut);");
+            } else {
+                if (isCachedProperty(property)) {
+                    out.println("        looseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+                } else {
+                    out.println("        looseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+                }
+            }
+        }
+    }
+
+    protected void generateLooseUnmarshalBody(PrintWriter out) {
+        for (JProperty property : getProperties()) {
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String propertyTypeName = propertyType.getSimpleName();
+
+            if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
+                generateLooseUnmarshalBodyForArrayProperty(out, property, size);
+            } else {
+                generateLooseUnmarshalBodyForProperty(out, property, size);
+            }
+        }
+    }
+
+    protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+        String setter = property.getSetter().getSimpleName();
+        String type = property.getType().getSimpleName();
+
+        if (type.equals("boolean")) {
+            out.println("        info." + setter + "(dataIn.readBoolean());");
+        } else if (type.equals("byte")) {
+            out.println("        info." + setter + "(dataIn.readByte());");
+        } else if (type.equals("char")) {
+            out.println("        info." + setter + "(dataIn.readChar());");
+        } else if (type.equals("short")) {
+            out.println("        info." + setter + "(dataIn.readShort());");
+        } else if (type.equals("int")) {
+            out.println("        info." + setter + "(dataIn.readInt());");
+        } else if (type.equals("long")) {
+            out.println("        info." + setter + "(looseUnmarshalLong(wireFormat, dataIn));");
+        } else if (type.equals("String")) {
+            out.println("        info." + setter + "(looseUnmarshalString(dataIn));");
+        } else if (type.equals("byte[]")) {
+            if (size != null) {
+                out.println("        info." + setter + "(looseUnmarshalConstByteArray(dataIn, " + size.asInt() + "));");
+            } else {
+                out.println("        info." + setter + "(looseUnmarshalByteArray(dataIn));");
+            }
+        } else if (type.equals("ByteSequence")) {
+            out.println("        info." + setter + "(looseUnmarshalByteSequence(dataIn));");
+        } else if (isThrowable(property.getType())) {
+            out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalThrowable(wireFormat, dataIn));");
+        } else if (isCachedProperty(property)) {
+            out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalCachedObject(wireFormat, dataIn));");
+        } else {
+            out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalNestedObject(wireFormat, dataIn));");
+        }
+    }
+
+    protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+        JClass propertyType = property.getType();
+        String arrayType = propertyType.getArrayComponentType().getQualifiedName();
+        String setter = property.getSetter().getSimpleName();
+        out.println();
+        if (size != null) {
+            out.println("        {");
+            out.println("            " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
+            out.println("            " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
+            out.println("            }");
+            out.println("            info." + setter + "(value);");
+            out.println("        }");
+        } else {
+            out.println("        if (dataIn.readBoolean()) {");
+            out.println("            short size = dataIn.readShort();");
+            out.println("            " + arrayType + " value[] = new " + arrayType + "[size];");
+            out.println("            for( int i=0; i < size; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
+            out.println("            }");
+            out.println("            info." + setter + "(value);");
+            out.println("        }");
+            out.println("        else {");
+            out.println("            info." + setter + "(null);");
+            out.println("        }");
+        }
+    }
+
+    /**
+     * Returns whether or not the given annotation has a mandatory flag on it or
+     * not
+     */
+    protected String getMandatoryFlag(JAnnotation annotation) {
+        JAnnotationValue value = annotation.getValue("mandatory");
+        if (value != null) {
+            String text = value.asString();
+            if (text != null && text.equalsIgnoreCase("true")) {
+                return "true";
+            }
+        }
+        return "false";
+    }
+
+    public List<JClass> getConcreteClasses() {
+        return concreteClasses;
+    }
+
+    public void setConcreteClasses(List<JClass> concreteClasses) {
+        this.concreteClasses = concreteClasses;
+    }
+
+    public File getFactoryFile() {
+        return factoryFile;
+    }
+
+    public void setFactoryFile(File factoryFile) {
+        this.factoryFile = factoryFile;
+    }
+
+    public String getFactoryFileName() {
+        return factoryFileName;
+    }
+
+    public void setFactoryFileName(String factoryFileName) {
+        this.factoryFileName = factoryFileName;
+    }
+
+    public String getIndent() {
+        return indent;
+    }
+
+    public void setIndent(String indent) {
+        this.indent = indent;
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MultiSourceGenerator.java
----------------------------------------------------------------------
diff --git a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MultiSourceGenerator.java b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MultiSourceGenerator.java
new file mode 100644
index 0000000..1a0bcd3
--- /dev/null
+++ b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/MultiSourceGenerator.java
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.generator;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.FixCRLF;
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+import org.codehaus.jam.JamClassIterator;
+
+/**
+ *
+ */
+public abstract class MultiSourceGenerator extends OpenWireGenerator {
+
+    protected Set<String> manuallyMaintainedClasses = new HashSet<String>();
+    protected File destDir;
+    protected File destFile;
+
+    protected JClass jclass;
+    protected JClass superclass;
+    protected String simpleName;
+    protected String className;
+    protected String baseClass;
+    protected StringBuffer buffer;
+
+    protected String targetDir;
+
+    public MultiSourceGenerator() {
+        initialiseManuallyMaintainedClasses();
+    }
+
+    public Object run() {
+        if (destDir == null) {
+            throw new IllegalArgumentException("No destDir defined!");
+        }
+        System.out.println(getClass().getName() + " generating files in: " + destDir);
+        destDir.mkdirs();
+        buffer = new StringBuffer();
+
+        JamClassIterator iter = getClasses();
+        while (iter.hasNext()) {
+            try {
+                jclass = iter.nextClass();
+                if (isValidClass(jclass)) {
+                    processClass(jclass);
+                }
+            } catch (Exception e) {
+                System.err.println("Unable to process: " + jclass);
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns all the valid properties available on the current class
+     */
+    public List<JProperty> getProperties() {
+        List<JProperty> answer = new ArrayList<JProperty>();
+        JProperty[] properties = jclass.getDeclaredProperties();
+        for (int i = 0; i < properties.length; i++) {
+            JProperty property = properties[i];
+            if (isValidProperty(property)) {
+                answer.add(property);
+            }
+        }
+        return answer;
+    }
+
+    protected boolean isValidClass(JClass jclass) {
+        JAnnotation annotation = jclass.getAnnotation("openwire:marshaller");
+        if (annotation == null) {
+            return false;
+        }
+
+        if (!includeInThisVersion(annotation)) {
+            return false;
+        }
+
+        return !manuallyMaintainedClasses.contains(jclass.getSimpleName());
+    }
+
+    protected void processClass(JClass jclass) {
+        simpleName = jclass.getSimpleName();
+        superclass = jclass.getSuperclass();
+
+        System.out.println(getClass().getName() + " processing class: " + simpleName);
+
+        className = getClassName(jclass);
+        destFile = new File(destDir, className + filePostFix);
+        baseClass = getBaseClassName(jclass);
+
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileWriter(destFile));
+            generateFile(out);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (out != null) {
+                out.close();
+            }
+        }
+
+        // Use the FixCRLF Ant Task to make sure the file has consistent
+        // newlines so that SVN does not complain on checkin.
+        Project project = new Project();
+        project.init();
+        FixCRLF fixCRLF = new FixCRLF();
+        fixCRLF.setProject(project);
+        fixCRLF.setSrcdir(destFile.getParentFile());
+        fixCRLF.setIncludes(destFile.getName());
+        fixCRLF.execute();
+    }
+
+    protected abstract void generateFile(PrintWriter out) throws Exception;
+
+    protected String getBaseClassName(JClass jclass) {
+        String answer = "BaseDataStructure";
+        if (superclass != null) {
+            String name = superclass.getSimpleName();
+            if (name != null && !name.equals("Object")) {
+                answer = name;
+            }
+        }
+        return answer;
+    }
+
+    protected String getClassName(JClass jclass) {
+        return jclass.getSimpleName();
+    }
+
+    public boolean isAbstractClass() {
+        return jclass != null && jclass.isAbstract();
+    }
+
+    public String getAbstractClassText() {
+        return isAbstractClass() ? "abstract " : "";
+    }
+
+    public boolean isMarshallerAware() {
+        return isMarshallAware(jclass);
+    }
+
+    protected void initialiseManuallyMaintainedClasses() {
+        String[] names = {
+            "OpenWireDestination",
+            "OpenWireTempDestination",
+            "OpenWireQueue",
+            "OpenWireTopic",
+            "OpenWireTempQueue",
+            "OpenWireTempTopic",
+            "OpenWireMessage",
+            "OpenWireTextMessage",
+            "OpenWireMapMessage",
+            "OpenWireBytesMessage",
+            "OpenWireStreamMessage",
+            "OpenWireBlobMessage",
+            "OpenWireObjectMessage",
+            "BaseCommand",
+            "DataStructureSupport",
+            "WireFormatInfo"
+        };
+
+        for (int i = 0; i < names.length; i++) {
+            manuallyMaintainedClasses.add(names[i]);
+        }
+    }
+
+    public String getBaseClass() {
+        return baseClass;
+    }
+
+    public void setBaseClass(String baseClass) {
+        this.baseClass = baseClass;
+    }
+
+    public String getClassName() {
+        return className;
+    }
+
+    public void setClassName(String className) {
+        this.className = className;
+    }
+
+    public File getDestDir() {
+        return destDir;
+    }
+
+    public void setDestDir(File destDir) {
+        this.destDir = destDir;
+    }
+
+    public File getDestFile() {
+        return destFile;
+    }
+
+    public void setDestFile(File destFile) {
+        this.destFile = destFile;
+    }
+
+    public JClass getJclass() {
+        return jclass;
+    }
+
+    public void setJclass(JClass jclass) {
+        this.jclass = jclass;
+    }
+
+    public Set<String> getManuallyMaintainedClasses() {
+        return manuallyMaintainedClasses;
+    }
+
+    public void setManuallyMaintainedClasses(Set<String> manuallyMaintainedClasses) {
+        this.manuallyMaintainedClasses = manuallyMaintainedClasses;
+    }
+
+    public String getSimpleName() {
+        return simpleName;
+    }
+
+    public void setSimpleName(String simpleName) {
+        this.simpleName = simpleName;
+    }
+
+    public JClass getSuperclass() {
+        return superclass;
+    }
+
+    public void setSuperclass(JClass superclass) {
+        this.superclass = superclass;
+    }
+
+    public String getTargetDir() {
+        return targetDir;
+    }
+
+    public void setTargetDir(String sourceDir) {
+        this.targetDir = sourceDir;
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireGenerator.java
----------------------------------------------------------------------
diff --git a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireGenerator.java b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireGenerator.java
new file mode 100644
index 0000000..dfd9a61
--- /dev/null
+++ b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireGenerator.java
@@ -0,0 +1,178 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.generator;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JAnnotationValue;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JField;
+import org.codehaus.jam.JMethod;
+import org.codehaus.jam.JProperty;
+import org.codehaus.jam.JamClassIterator;
+import org.codehaus.jam.JamService;
+
+/**
+ *
+ */
+public abstract class OpenWireGenerator {
+
+    protected int openwireVersion;
+    protected String filePostFix = ".java";
+    protected JamService jam;
+
+    protected String commandsPackage = "org.apache.activemq.openwire.commands";
+    protected String codecPackageRoot = "org.apache.activemq.openwire.codec";
+
+    public boolean isValidProperty(JProperty it) {
+        JMethod getter = it.getGetter();
+        JMethod setter = it.getSetter();
+
+        if (getter == null || setter == null || getter.isStatic()) {
+            return false;
+        }
+
+        JAnnotation annotation = getter.getAnnotation("openwire:property");
+        if (annotation == null) {
+            return false;
+        }
+
+        return true;
+    }
+
+    public boolean includeInThisVersion(JAnnotation annotation) {
+        JAnnotationValue value = annotation.getValue("version");
+        if (value != null && value.asInt() <= getOpenwireVersion()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    public boolean isCachedProperty(JProperty it) {
+        JMethod getter = it.getGetter();
+        if (!isValidProperty(it)) {
+            return false;
+        }
+        JAnnotationValue value = getter.getAnnotation("openwire:property").getValue("cache");
+        return value != null && value.asBoolean();
+    }
+
+    public boolean isAbstract(JClass j) {
+        JField[] fields = j.getFields();
+        for (int i = 0; i < fields.length; i++) {
+            JField field = fields[i];
+            if (field.isStatic() && field.isPublic() && field.isFinal() && field.getSimpleName().equals("DATA_STRUCTURE_TYPE")) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public boolean isThrowable(JClass j) {
+        if (j.getQualifiedName().equals(Throwable.class.getName())) {
+            return true;
+        }
+        return j.getSuperclass() != null && isThrowable(j.getSuperclass());
+    }
+
+    public boolean isMarshallAware(JClass j) {
+        if (filePostFix.endsWith("java")) {
+            JClass[] interfaces = j.getInterfaces();
+            for (int i = 0; i < interfaces.length; i++) {
+                if (interfaces[i].getQualifiedName().equals("org.apache.activemq.command.MarshallAware")) {
+                    return true;
+                }
+            }
+            return false;
+        } else {
+            String simpleName = j.getSimpleName();
+            return simpleName.equals("ActiveMQMessage") || simpleName.equals("WireFormatInfo");
+        }
+    }
+
+    public JamService getJam() {
+        return jam;
+    }
+
+    public JamClassIterator getClasses() {
+        return getJam().getClasses();
+    }
+
+    public int getOpenwireVersion() {
+        return openwireVersion;
+    }
+
+    public void setOpenwireVersion(int openwireVersion) {
+        this.openwireVersion = openwireVersion;
+    }
+
+    public String getCommandsPackage() {
+        return commandsPackage;
+    }
+
+    public void setCommandsPackage(String commandsPacakge) {
+        this.commandsPackage = commandsPacakge;
+    }
+
+    public String getCodecPackageRoot() {
+        return codecPackageRoot;
+    }
+
+    public void setCodecPackageRoot(String codecPackageRoot) {
+        this.codecPackageRoot = codecPackageRoot;
+    }
+
+    public String getOpenWireOpCode(JClass element) {
+        if (element != null) {
+            JAnnotation annotation = element.getAnnotation("openwire:marshaller");
+            return stringValue(annotation, "code", "0");
+        }
+        return "0";
+    }
+
+    protected String stringValue(JAnnotation annotation, String name) {
+        return stringValue(annotation, name, null);
+    }
+
+    protected String stringValue(JAnnotation annotation, String name, String defaultValue) {
+        if (annotation != null) {
+            JAnnotationValue value = annotation.getValue(name);
+            if (value != null) {
+                return value.asString();
+            }
+        }
+        return defaultValue;
+    }
+
+    public void setJam(JamService jam) {
+        this.jam = jam;
+    }
+
+    public String decapitalize(String text) {
+        if (text == null) {
+            return null;
+        }
+        return text.substring(0, 1).toLowerCase() + text.substring(1);
+    }
+
+    public String capitalize(String text) {
+        if (text == null) {
+            return null;
+        }
+        return text.substring(0, 1).toUpperCase() + text.substring(1);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestDataGenerator.java
----------------------------------------------------------------------
diff --git a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestDataGenerator.java b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestDataGenerator.java
new file mode 100644
index 0000000..6951a91
--- /dev/null
+++ b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestDataGenerator.java
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.generator;
+
+/**
+ * A simple helper class to help auto-generate test data when code generating test cases
+ *
+ *
+ */
+public class TestDataGenerator {
+    private int stringCounter;
+
+    private boolean boolCounter;
+    private byte byteCounter;
+    private char charCounter = 'a';
+    private short shortCounter;
+    private int intCounter;
+    private long longCounter;
+
+    public String createByte() {
+        return "(byte) " + (++byteCounter);
+    }
+
+    public String createChar() {
+        return "'" + (charCounter++) + "'";
+    }
+
+    public String createShort() {
+        return "(short) " + (++shortCounter);
+    }
+
+    public int createInt() {
+        return ++intCounter;
+    }
+
+    public long createLong() {
+        return ++longCounter;
+    }
+
+    public String createString(String property) {
+        return property + ":" + (++stringCounter);
+    }
+
+    public boolean createBool() {
+        boolCounter = !boolCounter;
+        return boolCounter;
+    }
+
+    public String createByteArray(String property) {
+        return "\"" + createString(property) + "\".getBytes()";
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestsGenerator.java
----------------------------------------------------------------------
diff --git a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestsGenerator.java b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestsGenerator.java
new file mode 100644
index 0000000..5e7e6f9
--- /dev/null
+++ b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/TestsGenerator.java
@@ -0,0 +1,198 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.generator;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.List;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JPackage;
+import org.codehaus.jam.JProperty;
+
+/**
+ * Generates the test classes for the OpenWire marshalers.
+ */
+public class TestsGenerator extends MultiSourceGenerator {
+
+    public TestsGenerator() {
+        this.targetDir = "src/test/java";
+    }
+
+    @Override
+    public Object run() {
+        if (destDir == null) {
+            destDir = new File(targetDir + "/io/openwire/codec/v" + getOpenwireVersion());
+        }
+        return super.run();
+    }
+
+    @Override
+    protected String getClassName(JClass jclass) {
+        if (isAbstract(jclass)) {
+            return super.getClassName(jclass) + "TestSupport";
+        } else {
+            return super.getClassName(jclass) + "Test";
+        }
+    }
+
+    @Override
+    protected String getBaseClassName(JClass jclass) {
+        String answer = "DataFileGeneratorTestSupport";
+        if (superclass != null) {
+            String name = superclass.getSimpleName();
+            if (name != null && !name.equals("JNDIBaseStorable") && !name.equals("DataStructureSupport") && !name.equals("Object")) {
+                answer = name + "Test";
+                if (isAbstract(getJclass().getSuperclass())) {
+                    answer += "Support";
+                }
+            }
+        }
+        return answer;
+    }
+
+    private void generateLicence(PrintWriter out) {
+        out.println("/**");
+        out.println(" *");
+        out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+        out.println(" * contributor license agreements.  See the NOTICE file distributed with");
+        out.println(" * this work for additional information regarding copyright ownership.");
+        out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+        out.println(" * (the \"License\"); you may not use this file except in compliance with");
+        out.println(" * the License.  You may obtain a copy of the License at");
+        out.println(" *");
+        out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+        out.println(" *");
+        out.println(" * Unless required by applicable law or agreed to in writing, software");
+        out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+        out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+        out.println(" * See the License for the specific language governing permissions and");
+        out.println(" * limitations under the License.");
+        out.println(" */");
+    }
+
+    @Override
+    protected void generateFile(PrintWriter out) {
+
+        generateLicence(out);
+
+        out.println("package " + getCodecPackageRoot() + ".v" + openwireVersion + ";");
+        out.println("");
+        out.println("import java.io.DataInputStream;");
+        out.println("import java.io.DataOutputStream;");
+        out.println("import java.io.IOException;");
+        out.println("");
+        out.println("import " + getCodecPackageRoot() + ".*;");
+        out.println("import " + getCommandsPackage() + ".*;");
+        out.println("");
+
+        for (JPackage pkg : getJclass().getImportedPackages()) {
+            for (JClass clazz : pkg.getClasses()) {
+                out.println("import " + clazz.getQualifiedName() + ";");
+            }
+        }
+
+        out.println("");
+        out.println("/**");
+        out.println(" * Test case for the OpenWire marshalling for " + jclass.getSimpleName() + "");
+        out.println(" *");
+        out.println(" * NOTE!: This file is auto generated - do not modify!");
+        out.println(" * ");
+        out.println(" */");
+        out.println("public " + getAbstractClassText() + "class " + className + " extends " + baseClass + " {");
+        out.println("");
+        if (!isAbstractClass()) {
+            out.println("");
+            out.println("    public static " + jclass.getSimpleName() + "Test SINGLETON = new " + jclass.getSimpleName() + "Test();");
+            out.println("");
+            out.println("    public Object createObject() throws Exception {");
+            out.println("        " + jclass.getSimpleName() + " info = new " + jclass.getSimpleName() + "();");
+            out.println("        populateObject(info);");
+            out.println("        return info;");
+            out.println("    }");
+        }
+        out.println("");
+        out.println("    protected void populateObject(Object object) throws Exception {");
+        out.println("        super.populateObject(object);");
+        out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ") object;");
+        out.println("");
+
+        TestDataGenerator generator = new TestDataGenerator();
+
+        List<JProperty> properties = getProperties();
+        for (JProperty property : properties) {
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            String size = stringValue(annotation, "size");
+            String testSize = stringValue(annotation, "testSize");
+            String type = property.getType().getSimpleName();
+            String propertyName = property.getSimpleName();
+            if ("-1".equals(testSize)) {
+                continue;
+            }
+
+            String setterName = property.getSetter().getSimpleName();
+
+            if (type.equals("boolean")) {
+                out.println("        info." + setterName + "(" + generator.createBool() + ");");
+            } else if (type.equals("byte")) {
+                out.println("        info." + setterName + "(" + generator.createByte() + ");");
+            } else if (type.equals("char")) {
+                out.println("        info." + setterName + "(" + generator.createChar() + ");");
+            } else if (type.equals("short")) {
+                out.println("        info." + setterName + "(" + generator.createShort() + ");");
+            } else if (type.equals("int")) {
+                out.println("        info." + setterName + "(" + generator.createInt() + ");");
+            } else if (type.equals("long")) {
+                out.println("        info." + setterName + "(" + generator.createLong() + ");");
+            } else if (type.equals("byte[]")) {
+                out.println("        info." + setterName + "(" + generator.createByteArray(propertyName) + ");");
+            } else if (type.equals("String")) {
+                out.println("        info." + setterName + "(\"" + generator.createString(propertyName) + "\");");
+            } else if (type.equals("ByteSequence")) {
+                out.println("        {");
+                out.println("            byte data[] = " + generator.createByteArray(propertyName) + ";");
+                out.println("            info." + setterName + "(new org.apache.activemq.util.ByteSequence(data,0,data.length));");
+                out.println("}");
+            } else if (type.equals("Throwable")) {
+                out.println("        info." + setterName + "(createThrowable(\"" + generator.createString(propertyName) + "\"));");
+            } else {
+                if (property.getType().isArrayType()) {
+                    String arrayType = property.getType().getArrayComponentType().getSimpleName();
+                    if (size == null) {
+                        size = "2";
+                    }
+                    if (arrayType == jclass.getSimpleName()) {
+                        size = "0";
+                    }
+                    out.println("        {");
+                    out.println("            " + arrayType + " value[] = new " + arrayType + "[" + size + "];");
+                    out.println("            for( int i=0; i < " + size + "; i++ ) {");
+                    out.println("                value[i] = create" + arrayType + "(\"" + generator.createString(propertyName) + "\");");
+                    out.println("            }");
+                    out.println("            info." + setterName + "(value);");
+                    out.println("        }");
+                } else {
+                    out.println("        info." + setterName + "(create" + type + "(\"" + generator.createString(propertyName) + "\"));");
+                }
+            }
+        }
+
+        out.println("    }");
+        out.println("}");
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-interop-tests/.gitignore
----------------------------------------------------------------------
diff --git a/openwire-interop-tests/.gitignore b/openwire-interop-tests/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/openwire-interop-tests/.gitignore
@@ -0,0 +1 @@
+/target

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-interop-tests/pom.xml
----------------------------------------------------------------------
diff --git a/openwire-interop-tests/pom.xml b/openwire-interop-tests/pom.xml
new file mode 100644
index 0000000..be6174f
--- /dev/null
+++ b/openwire-interop-tests/pom.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  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 License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.activemq</groupId>
+    <artifactId>openwire-protocol</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>openwire-interop-tests</artifactId>
+  <name>openwire-interop-tests</name>
+  <description>Set of interop tests to ensure that the OpenWire codec works with ActiveMQ</description>
+  <packaging>jar</packaging>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <!-- =================================== -->
+    <!-- Test Dependencies               -->
+    <!-- =================================== -->
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>openwire-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>openwire-legacy</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.fusesource.hawtbuf</groupId>
+      <artifactId>hawtbuf</artifactId>
+    </dependency>
+
+    <!-- Pull in ActiveMQ for compatibility testing -->
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-broker</artifactId>
+      <version>${activemq-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-kahadb-store</artifactId>
+      <version>${activemq-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-jaas</artifactId>
+      <version>${activemq-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-spring</artifactId>
+      <version>${activemq-version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java
----------------------------------------------------------------------
diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java
new file mode 100644
index 0000000..7aa97d1
--- /dev/null
+++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java
@@ -0,0 +1,438 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.codec;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.TimeUnit;
+
+import javax.jms.BytesMessage;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQBytesMessage;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTextMessage;
+import org.apache.activemq.openwire.commands.ConnectionInfo;
+import org.apache.activemq.openwire.commands.ConsumerInfo;
+import org.apache.activemq.openwire.commands.Message;
+import org.apache.activemq.openwire.commands.MessageAck;
+import org.apache.activemq.openwire.commands.OpenWireBytesMessage;
+import org.apache.activemq.openwire.commands.OpenWireQueue;
+import org.apache.activemq.openwire.commands.OpenWireTextMessage;
+import org.apache.activemq.openwire.commands.ProducerInfo;
+import org.apache.activemq.openwire.util.Wait;
+import org.apache.activemq.openwire.utils.OpenWireConnection;
+import org.apache.activemq.openwire.utils.OpenWireConsumer;
+import org.apache.activemq.openwire.utils.OpenWireProducer;
+import org.apache.activemq.openwire.utils.OpenWireSession;
+import org.junit.Test;
+
+public class MessageCompressionTest extends OpenWireInteropTestSupport {
+
+    // The following text should compress well
+    private static final String TEXT = "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+            + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. ";
+
+    public OpenWireQueue getOpenWireQueue() {
+        return new OpenWireQueue(name.getMethodName());
+    }
+
+    public Queue getActiveMQQueue() {
+        return new ActiveMQQueue(name.getMethodName());
+    }
+
+    @Test
+    public void testTextMessageCompressionActiveMQ() throws Exception {
+        sendAMQTextMessage(TEXT);
+        ActiveMQTextMessage message = receiveAMQTextMessage();
+        int compressedSize = message.getContent().getLength();
+
+        sendAMQTextMessage(TEXT, false);
+        message = receiveAMQTextMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    @Test
+    public void testOpenWireTextMessageCompression() throws Exception {
+        sendOpenWireTextMessage(TEXT);
+        OpenWireTextMessage message = receiveOpenWireTextMessage();
+        int compressedSize = message.getContent().getLength();
+
+        sendOpenWireTextMessage(TEXT, false);
+        message = receiveOpenWireTextMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    @Test
+    public void testTextMessageCompressionActiveMQtoOpenWire() throws Exception {
+        sendAMQTextMessage(TEXT);
+        OpenWireTextMessage message = receiveOpenWireTextMessage();
+        int compressedSize = message.getContent().getLength();
+
+        sendAMQTextMessage(TEXT, false);
+        message = receiveOpenWireTextMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    @Test
+    public void testTextMessageCompressionOpenWireToActiveMQ() throws Exception {
+        sendOpenWireTextMessage(TEXT);
+        ActiveMQTextMessage message = receiveAMQTextMessage();
+        int compressedSize = message.getContent().getLength();
+
+        sendOpenWireTextMessage(TEXT, false);
+        message = receiveAMQTextMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    @Test
+    public void testBytesMessageCompressionActiveMQ() throws Exception {
+        sendAMQBytesMessage(TEXT);
+        ActiveMQBytesMessage message = receiveAMQBytesMessage();
+        int compressedSize = message.getContent().getLength();
+        byte[] bytes = new byte[TEXT.getBytes("UTF8").length];
+        message.readBytes(bytes);
+        assertTrue(message.readBytes(new byte[255]) == -1);
+        String rcvString = new String(bytes, "UTF8");
+        assertEquals(TEXT, rcvString);
+        assertTrue(message.isCompressed());
+
+        sendAMQBytesMessage(TEXT, false);
+        message = receiveAMQBytesMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    @Test
+    public void testBytesMessageCompressionOpenWire() throws Exception {
+        sendOpenWireBytesMessage(TEXT);
+        OpenWireBytesMessage message = receiveOpenWireBytesMessage();
+        int compressedSize = message.getContent().getLength();
+        byte[] bytes = message.getBodyBytes();
+        String rcvString = new String(bytes, "UTF8");
+        assertEquals(TEXT, rcvString);
+        assertTrue(message.isCompressed());
+
+        sendOpenWireBytesMessage(TEXT, false);
+        message = receiveOpenWireBytesMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    @Test
+    public void testBytesMessageCompressionActiveMQtoOpenWire() throws Exception {
+        sendAMQBytesMessage(TEXT);
+        OpenWireBytesMessage message = receiveOpenWireBytesMessage();
+        int compressedSize = message.getContent().getLength();
+        byte[] bytes = message.getBodyBytes();
+        String rcvString = new String(bytes, "UTF8");
+        assertEquals(TEXT, rcvString);
+        assertTrue(message.isCompressed());
+
+        sendAMQBytesMessage(TEXT, false);
+        message = receiveOpenWireBytesMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    @Test
+    public void testBytesMessageCompressionOpenWiretoActiveMQ() throws Exception {
+        sendAMQBytesMessage(TEXT);
+        OpenWireBytesMessage message = receiveOpenWireBytesMessage();
+        int compressedSize = message.getContent().getLength();
+        byte[] bytes = message.getBodyBytes();
+        String rcvString = new String(bytes, "UTF8");
+        assertEquals(TEXT, rcvString);
+        assertTrue(message.isCompressed());
+
+        sendAMQBytesMessage(TEXT, false);
+        message = receiveOpenWireBytesMessage();
+        int unCompressedSize = message.getContent().getLength();
+
+        assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+                   compressedSize < unCompressedSize);
+    }
+
+    //---------- Sends and Receives Message Via ActiveMQ Objects -------------//
+
+    private void sendAMQTextMessage(String message) throws Exception {
+        sendAMQTextMessage(TEXT, true);
+    }
+
+    private void sendAMQTextMessage(String message, boolean useCompression) throws Exception {
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI);
+        factory.setUseCompression(useCompression);
+        ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageProducer producer = session.createProducer(getActiveMQQueue());
+        producer.send(session.createTextMessage(message));
+        connection.close();
+    }
+
+    private ActiveMQTextMessage receiveAMQTextMessage() throws Exception {
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI);
+        ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageConsumer consumer = session.createConsumer(getActiveMQQueue());
+        ActiveMQTextMessage rc = (ActiveMQTextMessage) consumer.receive();
+        connection.close();
+        return rc;
+    }
+
+    private void sendAMQBytesMessage(String message) throws Exception {
+        sendAMQBytesMessage(TEXT, true);
+    }
+
+    private void sendAMQBytesMessage(String message, boolean useCompression) throws Exception {
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI);
+        factory.setUseCompression(useCompression);
+        ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageProducer producer = session.createProducer(getActiveMQQueue());
+        BytesMessage bytesMessage = session.createBytesMessage();
+        bytesMessage.writeBytes(message.getBytes("UTF8"));
+        producer.send(bytesMessage);
+        connection.close();
+    }
+
+    private ActiveMQBytesMessage receiveAMQBytesMessage() throws Exception {
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI);
+        ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageConsumer consumer = session.createConsumer(getActiveMQQueue());
+        ActiveMQBytesMessage rc = (ActiveMQBytesMessage) consumer.receive();
+        connection.close();
+        return rc;
+    }
+
+    //---------- Send and Receive OpenWire Messages --------------------------//
+
+    private void sendOpenWireTextMessage(String payload) throws Exception {
+        sendOpenWireTextMessage(payload, true);
+    }
+
+    private void sendOpenWireTextMessage(String payload, boolean useCompression) throws Exception {
+        connect();
+        assertTrue(awaitConnected(10, TimeUnit.SECONDS));
+        OpenWireConnection connection = new OpenWireConnection();
+        ConnectionInfo connectionInfo = connection.createConnectionInfo();
+        connectionInfo.setClientId(name.getMethodName());
+        assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount());
+
+        OpenWireSession sessionId = connection.createOpenWireSession();
+        assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS));
+        OpenWireProducer producerId = sessionId.createOpenWireProducer();
+
+        ProducerInfo info = producerId.createProducerInfo(getOpenWireQueue());
+        info.setDispatchAsync(false);
+        assertTrue(request(info, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getQueueProducers().length);
+
+        OpenWireTextMessage message = new OpenWireTextMessage();
+        message.setUseCompression(useCompression);
+        message.setText(payload);
+        message.setTimestamp(System.currentTimeMillis());
+        message.setMessageId(producerId.getNextMessageId());
+        message.setProducerId(producerId.getProducerId());
+        message.setDestination(getOpenWireQueue());
+        message.onSend();
+
+        assertTrue(request(message, 10, TimeUnit.SECONDS));
+        assertEquals(1, getProxyToQueue(getOpenWireQueue().getPhysicalName()).getQueueSize());
+
+        assertTrue(request(connection.createRemoveInfo(), 10, TimeUnit.SECONDS));
+        assertEquals(0, brokerService.getAdminView().getCurrentConnectionsCount());
+        disconnect();
+    }
+
+    private void sendOpenWireBytesMessage(String payload) throws Exception {
+        sendOpenWireBytesMessage(payload, true);
+    }
+
+    private void sendOpenWireBytesMessage(String payload, boolean useCompression) throws Exception {
+        connect();
+        assertTrue(awaitConnected(10, TimeUnit.SECONDS));
+        OpenWireConnection connection = new OpenWireConnection();
+        ConnectionInfo connectionInfo = connection.createConnectionInfo();
+        connectionInfo.setClientId(name.getMethodName());
+        assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount());
+
+        OpenWireSession sessionId = connection.createOpenWireSession();
+        assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS));
+        OpenWireProducer producerId = sessionId.createOpenWireProducer();
+
+        ProducerInfo info = producerId.createProducerInfo(getOpenWireQueue());
+        info.setDispatchAsync(false);
+        assertTrue(request(info, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getQueueProducers().length);
+
+        OpenWireBytesMessage message = new OpenWireBytesMessage();
+        message.setUseCompression(useCompression);
+        message.setBodyBytes(payload.getBytes("UTF8"));
+        message.setTimestamp(System.currentTimeMillis());
+        message.setMessageId(producerId.getNextMessageId());
+        message.setProducerId(producerId.getProducerId());
+        message.setDestination(getOpenWireQueue());
+        message.onSend();
+
+        assertTrue(request(message, 10, TimeUnit.SECONDS));
+        assertEquals(1, getProxyToQueue(getOpenWireQueue().getPhysicalName()).getQueueSize());
+
+        assertTrue(request(connection.createRemoveInfo(), 10, TimeUnit.SECONDS));
+        assertEquals(0, brokerService.getAdminView().getCurrentConnectionsCount());
+        disconnect();
+    }
+
+    public OpenWireTextMessage receiveOpenWireTextMessage() throws Exception {
+        connect();
+        assertTrue(awaitConnected(10, TimeUnit.SECONDS));
+        OpenWireConnection connection = new OpenWireConnection();
+        ConnectionInfo connectionInfo = connection.createConnectionInfo();
+        connectionInfo.setClientId(name.getMethodName());
+        assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount());
+
+        OpenWireSession sessionId = connection.createOpenWireSession();
+        assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS));
+        assertEquals(1, getProxyToQueue(getOpenWireQueue().getPhysicalName()).getQueueSize());
+
+        OpenWireConsumer consumerId = sessionId.createOpenWireConsumer();
+        ConsumerInfo consumerInfo = consumerId.createConsumerInfo(getOpenWireQueue());
+        consumerInfo.setDispatchAsync(false);
+        consumerInfo.setPrefetchSize(1);
+        assertTrue(request(consumerInfo, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getQueueSubscribers().length);
+
+        assertTrue("Should have received a message", Wait.waitFor(new Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                return messages.size() == 1;
+            }
+        }));
+
+        Message incoming = messages.poll();
+        assertTrue(incoming instanceof OpenWireTextMessage);
+        OpenWireTextMessage received = (OpenWireTextMessage) incoming;
+
+        MessageAck ack = new MessageAck();
+        ack.setAckType(MessageAck.STANDARD_ACK_TYPE);
+        ack.setConsumerId(consumerId.getConsumerId());
+        ack.setDestination(getOpenWireQueue());
+        ack.setLastMessageId(received.getMessageId());
+        ack.setMessageCount(1);
+        assertTrue(request(ack, 60, TimeUnit.SECONDS));
+        assertEquals(0, getProxyToQueue(getOpenWireQueue().getPhysicalName()).getQueueSize());
+
+        assertTrue(request(connection.createRemoveInfo(), 10, TimeUnit.SECONDS));
+        assertEquals(0, brokerService.getAdminView().getCurrentConnectionsCount());
+        disconnect();
+
+        return received;
+    }
+
+    public OpenWireBytesMessage receiveOpenWireBytesMessage() throws Exception {
+        connect();
+        assertTrue(awaitConnected(10, TimeUnit.SECONDS));
+        OpenWireConnection connection = new OpenWireConnection();
+        ConnectionInfo connectionInfo = connection.createConnectionInfo();
+        connectionInfo.setClientId(name.getMethodName());
+        assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount());
+
+        OpenWireSession sessionId = connection.createOpenWireSession();
+        assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS));
+        assertEquals(1, getProxyToQueue(getOpenWireQueue().getPhysicalName()).getQueueSize());
+
+        OpenWireConsumer consumerId = sessionId.createOpenWireConsumer();
+        ConsumerInfo consumerInfo = consumerId.createConsumerInfo(getOpenWireQueue());
+        consumerInfo.setDispatchAsync(false);
+        consumerInfo.setPrefetchSize(1);
+        assertTrue(request(consumerInfo, 10, TimeUnit.SECONDS));
+        assertEquals(1, brokerService.getAdminView().getQueueSubscribers().length);
+
+        assertTrue("Should have received a message", Wait.waitFor(new Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                return messages.size() == 1;
+            }
+        }));
+
+        Message incoming = messages.poll();
+        assertTrue(incoming instanceof OpenWireBytesMessage);
+        OpenWireBytesMessage received = (OpenWireBytesMessage) incoming;
+
+        MessageAck ack = new MessageAck();
+        ack.setAckType(MessageAck.STANDARD_ACK_TYPE);
+        ack.setConsumerId(consumerId.getConsumerId());
+        ack.setDestination(getOpenWireQueue());
+        ack.setLastMessageId(received.getMessageId());
+        ack.setMessageCount(1);
+        assertTrue(request(ack, 60, TimeUnit.SECONDS));
+        assertEquals(0, getProxyToQueue(getOpenWireQueue().getPhysicalName()).getQueueSize());
+
+        assertTrue(request(connection.createRemoveInfo(), 10, TimeUnit.SECONDS));
+        assertEquals(0, brokerService.getAdminView().getCurrentConnectionsCount());
+        disconnect();
+
+        return received;
+    }
+
+    @Override
+    protected int getOpenWireVersion() {
+        return 10;
+    }
+
+    @Override
+    protected boolean isTightEncodingEnabled() {
+        return false;
+    }
+}


Mime
View raw message