first spike at getting the OpenWire.Net to work; also upgraded to latest groovy

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@366534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-01-06 17:11:53 +00:00
parent be19f9aabd
commit 606bba7b1e
5 changed files with 86 additions and 65 deletions

View File

@ -109,12 +109,10 @@
<classpath refid="openwire.classpath" />
<sysproperty key="openwire.version" value="${openwire.version}" />
<arg value="src/main/java/org/apache/activemq/command" />
<arg value="src/gram/script/GenerateCSharpClasses.groovy" />
<arg value="src/gram/script/GenerateCSharpMarshalling.groovy" />
<arg value="src/gram/script/GenerateJavaMarshalling.groovy" />
<arg value="src/gram/script/GenerateCMarshalling.groovy" />
<!--
<arg value="src/gram/script/GenerateCSharpClasses.groovy" />
<arg value="src/gram/script/GenerateCSharpMarshalling.groovy" />
-->
</java>
</goal>

View File

@ -259,7 +259,7 @@
<dependency>
<groupId>groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.0-jsr-01</version>
<version>1.0-jsr-04</version>
<type>jar</type>
</dependency>
<dependency>

View File

@ -285,7 +285,7 @@ out << """/**
"""
for (jclass in openwireClasses) {
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
def name = jclass.simpleName;
def type = ("ow_"+name).toUpperCase()+"_TYPE"
@ -337,7 +337,7 @@ apr_status_t ow_marshal1_${name}(ow_bit_buffer *buffer, ow_${name} *object)
ow_marshal1_${baseName}(buffer, (ow_${baseName}*)object);
"""
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
for (property in properties) {
def propname = toPropertyCase(property.simpleName);
def cached = isCachedProperty(property);
@ -345,7 +345,7 @@ apr_status_t ow_marshal1_${name}(ow_bit_buffer *buffer, ow_${name} *object)
def size = annotation.getValue("size");
out << " ";
def type = property.type.qualifiedName
type = property.type.qualifiedName
switch (type) {
case "boolean":
@ -404,7 +404,7 @@ apr_status_t ow_marshal2_${name}(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffe
ow_marshal2_${baseName}(buffer, bitbuffer, (ow_${baseName}*)object);
"""
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
for (property in properties) {
def annotation = property.getter.getAnnotation("openwire:property");
def size = annotation.getValue("size");
@ -412,7 +412,7 @@ apr_status_t ow_marshal2_${name}(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffe
def cached = isCachedProperty(property);
out << " "
def type = property.type.qualifiedName
type = property.type.qualifiedName
switch (type) {
case "boolean":
out << "ow_bit_buffer_read(bitbuffer);"; break;
@ -478,7 +478,7 @@ apr_status_t ow_unmarshal_${name}(ow_byte_array *buffer, ow_bit_buffer *bitbuffe
ow_unmarshal_${baseName}(buffer, bitbuffer, (ow_${baseName}*)object, pool);
"""
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
for (property in properties) {
def annotation = property.getter.getAnnotation("openwire:property");
def size = annotation.getValue("size");
@ -486,7 +486,7 @@ apr_status_t ow_unmarshal_${name}(ow_byte_array *buffer, ow_bit_buffer *bitbuffe
def cached = isCachedProperty(property);
out << " "
def type = property.type.qualifiedName
type = property.type.qualifiedName
switch (type) {
case "boolean":
out << "object->$propname = ow_bit_buffer_read(bitbuffer);"; break;

View File

@ -24,10 +24,12 @@ import org.apache.activemq.openwire.tool.OpenWireScript
class GenerateCSharpClasses extends OpenWireScript {
Object run() {
def destDir = new File("target/generated/dotnet/cs/org/apache/activemq/openwire")
def destDir = new File("../openwire-dotnet/src/OpenWire.Core/Commands")
destDir.mkdirs()
def messageClasses = classes.findAll { isMessageType(it) }
def messageClasses = classes.findAll {
it.getAnnotation("openwire:marshaller")!=null
}
println "Generating Java marshalling code to directory ${destDir}"
@ -43,7 +45,7 @@ class GenerateCSharpClasses extends OpenWireScript {
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
def file = new File(destDir, jclass.simpleName + ".cs")
String baseClass = "AbstractPacket"
String baseClass = "AbstractCommand"
if (jclass.superclass?.simpleName == "ActiveMQMessage") {
baseClass = "ActiveMQMessage"
}
@ -53,19 +55,21 @@ ${jclass.simpleName}.class
"""
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
*/
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;
namespace ActiveMQ
using OpenWire.Core;
namespace OpenWire.Core.Commands
{
public class ${jclass.simpleName} : $baseClass
{
@ -86,7 +90,7 @@ namespace ActiveMQ
// TODO generate ToString method
public overide int getPacketType() {
public override int GetCommandType() {
return ${getEnum(jclass)};
}
@ -97,21 +101,27 @@ namespace ActiveMQ
for (property in properties) {
def type = toCSharpType(property.type)
def name = decapitalize(property.simpleName)
def getter = property.getter.simpleName
def setter = property.setter.simpleName
def propertyName = property.simpleName
if (propertyName == jclass.simpleName) {
// TODO think of a better naming convention :)
propertyName += "Value"
}
def getter = capitalize(property.getter.simpleName)
def setter = capitalize(property.setter.simpleName)
out << """
public $type $getter()
public $type $propertyName
{
return this.$name;
get
{
return $name;
}
set
{
$name = value;
}
}
public void $setter($type $name)
{
this.$name = $name;
}
"""
}
@ -123,17 +133,25 @@ namespace ActiveMQ
}
}
def getEnum(type) {
return 1
}
def toCSharpType(type) {
def name = type.qualifiedName
switch (type) {
case "java.lang.String":
return "string"
case "boolean":
return "bool"
case "org.apache.activemq.command.DataStructure":
return "Command"
case "org.apache.activemq.message.ActiveMQDestination":
return "ActiveMQDestination"
case "org.apache.activemq.message.ActiveMQXid":
return "ActiveMQXid"
default:
return name
return type.simpleName
}
}
}

View File

@ -24,10 +24,12 @@ import org.apache.activemq.openwire.tool.OpenWireScript
class GenerateCSharpMarshalling extends OpenWireScript {
Object run() {
def destDir = new File("target/generated/dotnet/cs/org/apache/activemq/openwire/io")
def destDir = new File("../openwire-dotnet/src/OpenWire.Core/IO")
destDir.mkdirs()
def messageClasses = classes.findAll { isMessageType(it) }
def messageClasses = classes.findAll {
it.getAnnotation("openwire:marshaller")!=null
}
println "Generating Java marshalling code to directory ${destDir}"
@ -35,15 +37,17 @@ class GenerateCSharpMarshalling extends OpenWireScript {
int counter = 0
Map map = [:]
def propertyList = null
def type = null
for (jclass in messageClasses) {
println "Processing $jclass.simpleName"
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
propertyList = jclass.declaredProperties.findAll { isValidProperty(it) }
def file = new File(destDir, jclass.simpleName + "Marshaller.cs")
String baseClass = "AbstractPacketMarshaller"
String baseClass = "AbstractCommandMarshaller"
if (jclass.superclass?.simpleName == "ActiveMQMessage") {
baseClass = "ActiveMQMessageMarshaller"
}
@ -53,39 +57,40 @@ ${jclass.simpleName}Marshaller.class
"""
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
*/
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;
namespace ActiveMQ
using OpenWire.Core;
using OpenWire.Core.Commands;
using OpenWire.Core.IO;
namespace OpenWire.Core.IO
{
public class ${jclass.simpleName} : $baseClass
public class ${jclass.simpleName}Marshaller : $baseClass
{
public override int GetPacketType() {
return ${getEnum(jclass)};
}
public override Packet CreatePacket() {
public override Command CreateCommand() {
return new ${jclass.simpleName}();
}
public override void BuildPacket(Packet packet, DataInput dataIn) throws IOException {
super.buildPacket(packet, dataIn);
${jclass.simpleName} info = (${jclass.simpleName}) packet;
public override void BuildCommand(Command command, BinaryReader dataIn) {
super.buildCommand(command, dataIn);
${jclass.simpleName} info = (${jclass.simpleName}) command;
"""
for (property in properties) {
for (property in propertyList) {
out << " info.${property.setter.simpleName}("
def type = property.type.qualifiedName
type = property.type.qualifiedName
switch (type) {
case "java.lang.String":
out << "dataIn.readUTF()"
@ -137,15 +142,15 @@ namespace ActiveMQ
out << """
}
public override void WritePacket(Packet packet, DataOutput dataOut) throws IOException {
super.writePacket(packet, dataOut);
${jclass.simpleName} info = (${jclass.simpleName}) packet;
public override void WriteCommand(Command command, BinaryWriter dataOut) {
super.writeCommand(command, dataOut);
${jclass.simpleName} info = (${jclass.simpleName}) command;
"""
for (property in properties) {
for (property in propertyList) {
def getter = "info." + property.getter.simpleName + "()"
out << " "
def type = property.type.qualifiedName
type = property.type.qualifiedName
switch (type) {
case "java.lang.String":
out << "writeUTF($getter, dataOut);"