in openwire-generator/src/main/java/org/apache/activemq/openwire/generator/builtin/UniversalMarshallerGenerator.java [353:437]
private void writeTightMarshal2(PrintWriter out, OpenWireTypeDescriptor openWireType) {
out.println(" /**");
out.println(" * Write a object instance to data output stream");
out.println(" *");
out.println(" * @param wireFormat the OpenWireFormat instance to use");
out.println(" * @param source the object to marshal");
out.println(" * @param dataOut the DataOut where the properties are written");
out.println(" * @param bs the boolean stream where the type's booleans are written");
out.println(" *");
out.println(" * @throws IOException if an error occurs while writing the data");
out.println(" */");
out.println(" public void tightMarshal2(OpenWireFormat wireFormat, Object source, DataOutput dataOut, BooleanStream bs) throws IOException {");
out.println(" super.tightMarshal2(wireFormat, source, dataOut, bs);");
if (openWireType.hasProperties()) {
out.println("");
out.println(" " + openWireType.getTypeName() + " info = (" + openWireType.getTypeName() + ") source;");
if (isOpenWireVersionNeeded(openWireType)) {
out.println(" int version = wireFormat.getVersion();");
}
out.println("");
}
for (final OpenWirePropertyDescriptor property : openWireType.getProperties()) {
final int size = property.getSize();
final String typeName = property.getTypeName();
final String getter = "info." + property.getGetterName() + "()";
String indent = " ";
if (property.getVersion() > 1) {
indent = indent + " ";
out.println(" if (version >= " + property.getVersion() + ") {");
}
if (typeName.equals("boolean")) {
out.println(indent + "bs.readBoolean();");
} else if (typeName.equals("byte")) {
out.println(indent + "dataOut.writeByte(" + getter + ");");
} else if (typeName.equals("char")) {
out.println(indent + "dataOut.writeChar(" + getter + ");");
} else if (typeName.equals("short")) {
out.println(indent + "dataOut.writeShort(" + getter + ");");
} else if (typeName.equals("int")) {
out.println(indent + "dataOut.writeInt(" + getter + ");");
} else if (typeName.equals("long")) {
out.println(indent + "tightMarshalLong2(wireFormat, " + getter + ", dataOut, bs);");
} else if (typeName.equals("String")) {
out.println(indent + "tightMarshalString2(" + getter + ", dataOut, bs);");
} else if (typeName.equals("byte[]")) {
if (size > 0) {
out.println(indent + "tightMarshalConstByteArray2(" + getter + ", dataOut, bs, " + size + ");");
} else {
out.println(indent + "tightMarshalByteArray2(" + getter + ", dataOut, bs);");
}
} else if (typeName.equals("Buffer")) {
out.println(indent + "tightMarshalByteSequence2(" + getter + ", dataOut, bs);");
} else if (property.isArray()) {
if (size > 0) {
out.println(indent + "tightMarshalObjectArrayConstSize2(wireFormat, " + getter + ", dataOut, bs, " + size + ");");
} else {
out.println(indent + "tightMarshalObjectArray2(wireFormat, " + getter + ", dataOut, bs);");
}
} else if (property.isThrowable()) {
out.println(indent + "tightMarshalThrowable2(wireFormat, " + getter + ", dataOut, bs);");
} else {
if (property.isCached()) {
out.println(indent + "tightMarshalCachedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
} else {
out.println(indent + "tightMarshalNestedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
}
}
if (property.getVersion() > 1) {
out.println(" }");
}
}
if (openWireType.isMarshalAware()) {
out.println("");
out.println(" info.afterMarshall(wireFormat);");
}
out.println(" }");
out.println("");
}