in openwire-generator/src/main/java/org/apache/activemq/openwire/generator/builtin/UniversalMarshallerGenerator.java [543:626]
private void writeLooseMarshal(PrintWriter out, OpenWireTypeDescriptor openWireType) {
out.println(" /**");
out.println(" * Write the object to the output using loose marshaling.");
out.println(" *");
out.println(" * @throws IOException if an error occurs while writing the data");
out.println(" */");
out.println(" public void looseMarshal(OpenWireFormat wireFormat, Object source, DataOutput dataOut) throws IOException {");
if (openWireType.hasProperties()) {
out.println(" " + openWireType.getTypeName() + " info = (" + openWireType.getTypeName() + ") source;");
if (isOpenWireVersionNeeded(openWireType)) {
out.println(" int version = wireFormat.getVersion();");
}
out.println("");
}
if (openWireType.isMarshalAware()) {
out.println(" info.beforeMarshall(wireFormat);");
}
out.println(" super.looseMarshal(wireFormat, source, dataOut);");
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 + "dataOut.writeBoolean(" + getter + ");");
} 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 + "looseMarshalLong(wireFormat, " + getter + ", dataOut);");
} else if (typeName.equals("String")) {
out.println(indent + "looseMarshalString(" + getter + ", dataOut);");
} else if (typeName.equals("byte[]")) {
if (size > 0) {
out.println(indent + "looseMarshalConstByteArray(wireFormat, " + getter + ", dataOut, " + size + ");");
} else {
out.println(indent + "looseMarshalByteArray(wireFormat, " + getter + ", dataOut);");
}
} else if (typeName.equals("Buffer")) {
out.println(indent + "looseMarshalByteSequence(wireFormat, " + getter + ", dataOut);");
} else if (property.isArray()) {
if (size > 0) {
out.println(indent + "looseMarshalObjectArrayConstSize(wireFormat, " + getter + ", dataOut, " + size + ");");
} else {
out.println(indent + "looseMarshalObjectArray(wireFormat, " + getter + ", dataOut);");
}
} else if (property.isThrowable()) {
out.println(indent + "looseMarshalThrowable(wireFormat, " + getter + ", dataOut);");
} else {
if (property.isCached()) {
out.println(indent + "looseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
} else {
out.println(indent + "looseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
}
}
if (property.getVersion() > 1) {
out.println(" }");
}
}
if (openWireType.isMarshalAware()) {
out.println("");
out.println(" info.afterMarshall(wireFormat);");
}
out.println(" }");
out.println("");
}