nearly building OpenWire.Net; much closer now

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@366723 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-01-07 13:46:58 +00:00
parent 40280b7d31
commit 10681a29b8
2 changed files with 117 additions and 8 deletions

View File

@ -73,6 +73,8 @@ namespace OpenWire.Core.Commands
{
public class ${jclass.simpleName} : $baseClass
{
public const int ID_${jclass.simpleName} = ${getEnum(jclass)};
"""
for (property in properties) {
@ -91,7 +93,7 @@ namespace OpenWire.Core.Commands
public override int GetCommandType() {
return ${getEnum(jclass)};
return ID_${jclass.simpleName};
}

View File

@ -34,6 +34,8 @@ class GenerateCSharpMarshalling extends OpenWireScript {
println "Generating Java marshalling code to directory ${destDir}"
def buffer = new StringBuffer()
def readMethodBuffer = new StringBuffer()
def writeMethodBuffer = new StringBuffer()
int counter = 0
Map map = [:]
@ -54,11 +56,35 @@ class GenerateCSharpMarshalling extends OpenWireScript {
def notAbstract = jclass.simpleName != "ActiveMQDestination"
def abstractText = (notAbstract) ? "" : "abstract "
def marshallerType = jclass.simpleName + "Marshaller"
def marshallerField = decapitalize(marshallerType)
if (notAbstract) {
buffer << """
private static $marshallerType $marshallerField = new $marshallerType();
public static $marshallerType $marshallerType
{
get
{
return $marshallerField;
}
}
buffer << """
${jclass.simpleName}Marshaller.class
"""
readMethodBuffer << """
case ${jclass.simpleName}.ID_${jclass.simpleName}:
return ${marshallerField}.ReadCommand(dataIn);
"""
writeMethodBuffer << """
case ${jclass.simpleName}.ID_${jclass.simpleName}:
${marshallerField}.WriteCommand(command, dataOut);
"""
}
file.withWriter { out |
out << """//
// Marshalling code for Open Wire Format for ${jclass.simpleName}
@ -79,7 +105,7 @@ using OpenWire.Core.IO;
namespace OpenWire.Core.IO
{
public ${abstractText}class ${jclass.simpleName}Marshaller : $baseClass
public ${abstractText}class $marshallerType : $baseClass
{
"""
@ -120,6 +146,10 @@ namespace OpenWire.Core.IO
out << "dataIn.ReadByte()"
break;
case "byte[]":
out << "ReadBytes(dataIn)"
break;
case "char":
out << "dataIn.ReadChar()"
break;
@ -152,8 +182,16 @@ namespace OpenWire.Core.IO
out << "ReadBrokerIds(dataIn)"
break;
case "BrokerInfo[]":
out << "ReadBrokerInfos(dataIn)"
break;
case "DataStructure[]":
out << "ReadDataStructures(dataIn)"
break;
default:
out << "Read${type}(dataIn)"
out << "(${type}) CommandMarshallerRegistry.${type}Marshaller.ReadCommand(dataIn)"
}
out << """;
"""
@ -194,6 +232,10 @@ namespace OpenWire.Core.IO
out << "dataOut.Write($getter);"
break;
case "byte[]":
out << "WriteBytes($getter, dataOut);"
break;
case "char":
out << "dataOut.Write($getter);"
break;
@ -223,11 +265,19 @@ namespace OpenWire.Core.IO
break;
case "BrokerId[]":
out << "dataOut.WriteBrokerIds($getter);"
out << "WriteBrokerIds($getter, dataOut);"
break;
case "BrokerInfo[]":
out << "WriteBrokerInfos($getter, dataOut);"
break;
case "DataStructure[]":
out << "WriteDataStructures($getter, dataOut);"
break;
default:
out << "Write${type}($getter, dataOut);"
out << "CommandMarshallerRegistry.${type}Marshaller.WriteCommand($getter, dataOut);"
}
out << """
"""
@ -240,5 +290,62 @@ namespace OpenWire.Core.IO
"""
}
}
def file = new File(destDir, "CommandMarshallerRegistry.cs")
file.withWriter { out |
out << """//
// Marshalling code for Open Wire Format for ${jclass.simpleName}
//
//
// NOTE!: This file is autogenerated - do not modify!
// if you need to make a change, please see the Groovy scripts in the
// activemq-openwire module
//
using System;
using System.Collections;
using System.IO;
using OpenWire.Core;
using OpenWire.Core.Commands;
using OpenWire.Core.IO;
namespace OpenWire.Core.IO
{
public class CommandMarshallerRegistry
{
public static Command ReadCommand(BinaryReader dataIn)
{
byte commandID = dataIn.ReadByte();
switch (commandID)
{
$readMethodBuffer
default:
throw new Exception("Unknown command type: " + commandID);
}
}
public static void WriteCommand(Command command, BinaryWriter dataOut)
{
int commandID = command.CommandType;
dataOut.Write(commandID);
switch (commandID)
{
$readMethodBuffer
default:
throw new Exception("Unknown command type: " + commandID);
}
}
// Properties
$buffer
}
}
"""
}
}
}