diff --git a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java index 88d70aeb7b..f3b3f2c296 100644 --- a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java +++ b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java @@ -17,8 +17,10 @@ package org.apache.activemq.openwire.tool; import org.codehaus.jam.JClass; +import org.codehaus.jam.JProperty; -import java.io.File; +import java.io.*; +import java.util.Iterator; /** * @@ -34,6 +36,53 @@ public abstract class OpenWireCSharpClassesScript extends OpenWireClassesScript return super.run(); } + + public String makeHashCodeBody() throws Exception { + if (simpleName.endsWith("Id")) { + StringWriter buffer = new StringWriter(); + PrintWriter out = new PrintWriter(buffer); + out.println(" int answer = 0;"); + Iterator iter = getProperties().iterator(); + while (iter.hasNext()) { + JProperty property = (JProperty) iter.next(); + out.println(" answer = (answer * 37) + HashCode(" + property.getSimpleName() + ");"); + } + out.println(" return answer;"); + return buffer.toString(); + } + return null; + } + + public String makeEqualsBody() throws Exception { + if (simpleName.endsWith("Id")) { + StringWriter buffer = new StringWriter(); + PrintWriter out = new PrintWriter(buffer); + + Iterator iter = getProperties().iterator(); + while (iter.hasNext()) { + JProperty property = (JProperty) iter.next(); + String name = property.getSimpleName(); + out.println(" if (! Equals(this." + name + ", that." + name + ")) return false;"); + } + out.println(" return true;"); + return buffer.toString(); + } + return null; + } + + public String makeToStringBody() throws Exception { + StringWriter buffer = new StringWriter(); + PrintWriter out = new PrintWriter(buffer); + out.println(" return GetType().Name + \"[\""); + Iterator iter = getProperties().iterator(); + while (iter.hasNext()) { + JProperty property = (JProperty) iter.next(); + String name = property.getSimpleName(); + out.println(" + \" " + name + "=\" + " + name); + } + out.println(" + \" ]\";"); + return buffer.toString(); + } } diff --git a/activemq-core/src/gram/script/GenerateCSharpClasses.groovy b/activemq-core/src/gram/script/GenerateCSharpClasses.groovy index 86f68b4e48..f0e79d6880 100755 --- a/activemq-core/src/gram/script/GenerateCSharpClasses.groovy +++ b/activemq-core/src/gram/script/GenerateCSharpClasses.groovy @@ -69,13 +69,41 @@ namespace OpenWire.Client.Commands """ } + def text = makeHashCodeBody() + if (text != null) out << +""" + public override int GetHashCode() { +$text + } + +""" + + text = makeEqualsBody() + if (text != null) out << +""" + public override bool Equals(object that) { + if (that is ${className}) { + return Equals((${className}) that); + } + return false; + } + + public virtual bool Equals(${className} that) { +$text + } + +""" + + text = makeToStringBody() + if (text != null) out << """ + public override string ToString() { +$text + } + +""" + out << """ - // TODO generate Equals method - // TODO generate GetHashCode method - // TODO generate ToString method - - public override byte GetDataStructureType() { return ID_${jclass.simpleName}; }