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" /> <classpath refid="openwire.classpath" />
<sysproperty key="openwire.version" value="${openwire.version}" /> <sysproperty key="openwire.version" value="${openwire.version}" />
<arg value="src/main/java/org/apache/activemq/command" /> <arg value="src/main/java/org/apache/activemq/command" />
<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/GenerateCSharpClasses.groovy" />
<arg value="src/gram/script/GenerateCSharpMarshalling.groovy" /> <arg value="src/gram/script/GenerateCSharpMarshalling.groovy" />
--> <arg value="src/gram/script/GenerateJavaMarshalling.groovy" />
<arg value="src/gram/script/GenerateCMarshalling.groovy" />
</java> </java>
</goal> </goal>

View File

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

View File

@ -285,7 +285,7 @@ out << """/**
""" """
for (jclass in openwireClasses) { for (jclass in openwireClasses) {
def properties = jclass.declaredProperties.findAll { isValidProperty(it) } properties = jclass.declaredProperties.findAll { isValidProperty(it) }
def name = jclass.simpleName; def name = jclass.simpleName;
def type = ("ow_"+name).toUpperCase()+"_TYPE" 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); ow_marshal1_${baseName}(buffer, (ow_${baseName}*)object);
""" """
def properties = jclass.declaredProperties.findAll { isValidProperty(it) } properties = jclass.declaredProperties.findAll { isValidProperty(it) }
for (property in properties) { for (property in properties) {
def propname = toPropertyCase(property.simpleName); def propname = toPropertyCase(property.simpleName);
def cached = isCachedProperty(property); 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"); def size = annotation.getValue("size");
out << " "; out << " ";
def type = property.type.qualifiedName type = property.type.qualifiedName
switch (type) { switch (type) {
case "boolean": 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); 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) { for (property in properties) {
def annotation = property.getter.getAnnotation("openwire:property"); def annotation = property.getter.getAnnotation("openwire:property");
def size = annotation.getValue("size"); 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); def cached = isCachedProperty(property);
out << " " out << " "
def type = property.type.qualifiedName type = property.type.qualifiedName
switch (type) { switch (type) {
case "boolean": case "boolean":
out << "ow_bit_buffer_read(bitbuffer);"; break; 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); 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) { for (property in properties) {
def annotation = property.getter.getAnnotation("openwire:property"); def annotation = property.getter.getAnnotation("openwire:property");
def size = annotation.getValue("size"); 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); def cached = isCachedProperty(property);
out << " " out << " "
def type = property.type.qualifiedName type = property.type.qualifiedName
switch (type) { switch (type) {
case "boolean": case "boolean":
out << "object->$propname = ow_bit_buffer_read(bitbuffer);"; break; 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 { class GenerateCSharpClasses extends OpenWireScript {
Object run() { 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() 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}" println "Generating Java marshalling code to directory ${destDir}"
@ -43,7 +45,7 @@ class GenerateCSharpClasses extends OpenWireScript {
def properties = jclass.declaredProperties.findAll { isValidProperty(it) } def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
def file = new File(destDir, jclass.simpleName + ".cs") def file = new File(destDir, jclass.simpleName + ".cs")
String baseClass = "AbstractPacket" String baseClass = "AbstractCommand"
if (jclass.superclass?.simpleName == "ActiveMQMessage") { if (jclass.superclass?.simpleName == "ActiveMQMessage") {
baseClass = "ActiveMQMessage" baseClass = "ActiveMQMessage"
} }
@ -53,19 +55,21 @@ ${jclass.simpleName}.class
""" """
file.withWriter { out | file.withWriter { out |
out << """/** out << """//
* Marshalling code for Open Wire Format for ${jclass.simpleName} // Marshalling code for Open Wire Format for ${jclass.simpleName}
* //
* //
* NOTE!: This file is autogenerated - do not modify! // NOTE!: This file is autogenerated - do not modify!
* if you need to make a change, please see the Groovy scripts in the // if you need to make a change, please see the Groovy scripts in the
* activemq-openwire module // activemq-openwire module
*/ //
using System; using System;
using System.Collections; using System.Collections;
namespace ActiveMQ using OpenWire.Core;
namespace OpenWire.Core.Commands
{ {
public class ${jclass.simpleName} : $baseClass public class ${jclass.simpleName} : $baseClass
{ {
@ -86,7 +90,7 @@ namespace ActiveMQ
// TODO generate ToString method // TODO generate ToString method
public overide int getPacketType() { public override int GetCommandType() {
return ${getEnum(jclass)}; return ${getEnum(jclass)};
} }
@ -97,21 +101,27 @@ namespace ActiveMQ
for (property in properties) { for (property in properties) {
def type = toCSharpType(property.type) def type = toCSharpType(property.type)
def name = decapitalize(property.simpleName) def name = decapitalize(property.simpleName)
def getter = property.getter.simpleName def propertyName = property.simpleName
def setter = property.setter.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 << """ out << """
public $type $getter() public $type $propertyName
{ {
return this.$name; get
}
public void $setter($type $name)
{ {
this.$name = $name; return $name;
}
set
{
$name = value;
}
} }
""" """
} }
@ -123,17 +133,25 @@ namespace ActiveMQ
} }
} }
def getEnum(type) {
return 1
}
def toCSharpType(type) { def toCSharpType(type) {
def name = type.qualifiedName def name = type.qualifiedName
switch (type) { switch (type) {
case "java.lang.String": case "java.lang.String":
return "string" return "string"
case "boolean":
return "bool"
case "org.apache.activemq.command.DataStructure":
return "Command"
case "org.apache.activemq.message.ActiveMQDestination": case "org.apache.activemq.message.ActiveMQDestination":
return "ActiveMQDestination" return "ActiveMQDestination"
case "org.apache.activemq.message.ActiveMQXid": case "org.apache.activemq.message.ActiveMQXid":
return "ActiveMQXid" return "ActiveMQXid"
default: default:
return name return type.simpleName
} }
} }
} }

View File

@ -24,10 +24,12 @@ import org.apache.activemq.openwire.tool.OpenWireScript
class GenerateCSharpMarshalling extends OpenWireScript { class GenerateCSharpMarshalling extends OpenWireScript {
Object run() { 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() 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}" println "Generating Java marshalling code to directory ${destDir}"
@ -35,15 +37,17 @@ class GenerateCSharpMarshalling extends OpenWireScript {
int counter = 0 int counter = 0
Map map = [:] Map map = [:]
def propertyList = null
def type = null
for (jclass in messageClasses) { for (jclass in messageClasses) {
println "Processing $jclass.simpleName" 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") def file = new File(destDir, jclass.simpleName + "Marshaller.cs")
String baseClass = "AbstractPacketMarshaller" String baseClass = "AbstractCommandMarshaller"
if (jclass.superclass?.simpleName == "ActiveMQMessage") { if (jclass.superclass?.simpleName == "ActiveMQMessage") {
baseClass = "ActiveMQMessageMarshaller" baseClass = "ActiveMQMessageMarshaller"
} }
@ -53,39 +57,40 @@ ${jclass.simpleName}Marshaller.class
""" """
file.withWriter { out | file.withWriter { out |
out << """/** out << """//
* Marshalling code for Open Wire Format for ${jclass.simpleName} // Marshalling code for Open Wire Format for ${jclass.simpleName}
* //
* //
* NOTE!: This file is autogenerated - do not modify! // NOTE!: This file is autogenerated - do not modify!
* if you need to make a change, please see the Groovy scripts in the // if you need to make a change, please see the Groovy scripts in the
* activemq-openwire module // activemq-openwire module
*/ //
using System; using System;
using System.Collections; 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() { public override Command CreateCommand() {
return ${getEnum(jclass)};
}
public override Packet CreatePacket() {
return new ${jclass.simpleName}(); return new ${jclass.simpleName}();
} }
public override void BuildPacket(Packet packet, DataInput dataIn) throws IOException { public override void BuildCommand(Command command, BinaryReader dataIn) {
super.buildPacket(packet, dataIn); super.buildCommand(command, dataIn);
${jclass.simpleName} info = (${jclass.simpleName}) packet; ${jclass.simpleName} info = (${jclass.simpleName}) command;
""" """
for (property in properties) { for (property in propertyList) {
out << " info.${property.setter.simpleName}(" out << " info.${property.setter.simpleName}("
def type = property.type.qualifiedName type = property.type.qualifiedName
switch (type) { switch (type) {
case "java.lang.String": case "java.lang.String":
out << "dataIn.readUTF()" out << "dataIn.readUTF()"
@ -137,15 +142,15 @@ namespace ActiveMQ
out << """ out << """
} }
public override void WritePacket(Packet packet, DataOutput dataOut) throws IOException { public override void WriteCommand(Command command, BinaryWriter dataOut) {
super.writePacket(packet, dataOut); super.writeCommand(command, dataOut);
${jclass.simpleName} info = (${jclass.simpleName}) packet; ${jclass.simpleName} info = (${jclass.simpleName}) command;
""" """
for (property in properties) { for (property in propertyList) {
def getter = "info." + property.getter.simpleName + "()" def getter = "info." + property.getter.simpleName + "()"
out << " " out << " "
def type = property.type.qualifiedName type = property.type.qualifiedName
switch (type) { switch (type) {
case "java.lang.String": case "java.lang.String":
out << "writeUTF($getter, dataOut);" out << "writeUTF($getter, dataOut);"