diff --git a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java index 5dd8b78935..b6ad24c49d 100644 --- a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java +++ b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java @@ -16,13 +16,13 @@ */ package org.apache.activemq.openwire.tool; -import mx4j.tools.adaptor.http.GetAttributeCommandProcessor; - import org.codehaus.jam.JClass; +import org.codehaus.jam.JProperty; import org.codehaus.jam.JamClassIterator; import java.io.File; -import java.io.*; +import java.io.FileWriter; +import java.io.PrintWriter; import java.util.*; /** @@ -66,18 +66,33 @@ public abstract class OpenWireClassesScript extends OpenWireScript { return null; } + /** + * Returns all the valid properties available on the current class + */ + public List getProperties() { + List answer = new ArrayList(); + JProperty[] properties = jclass.getDeclaredProperties(); + for (int i = 0; i < properties.length; i++) { + JProperty property = properties[i]; + if (isValidProperty(property)) { + answer.add(property); + } + } + return answer; + } + protected boolean isValidClass(JClass jclass) { if (jclass.getAnnotation("openwire:marshaller") == null) { return false; } - return manuallyMaintainedClasses.contains(jclass.getSimpleName()); + return !manuallyMaintainedClasses.contains(jclass.getSimpleName()); } protected void processClass(JClass jclass) { simpleName = jclass.getSimpleName(); superclass = jclass.getSuperclass(); - System.out.println("Processing class: " + simpleName); + System.out.println(getClass().getName() + " processing class: " + simpleName); className = getClassName(jclass); @@ -88,6 +103,7 @@ public abstract class OpenWireClassesScript extends OpenWireScript { PrintWriter out = null; try { out = new PrintWriter(new FileWriter(destFile)); + generateFile(out); } catch (Exception e) { throw new RuntimeException(e); @@ -113,7 +129,7 @@ public abstract class OpenWireClassesScript extends OpenWireScript { } protected String getClassName(JClass jclass) { - return "AbstractCommand"; + return jclass.getSimpleName(); } } diff --git a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java new file mode 100644 index 0000000000..f2f7229760 --- /dev/null +++ b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java @@ -0,0 +1,70 @@ +/** + * + * Copyright 2005-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.openwire.tool; + +import org.codehaus.jam.JClass; + +import java.io.File; + +/** + * + * @version $Revision$ + */ +public abstract class OpenWireCppClassesScript extends OpenWireClassesScript { + + public Object run() { + filePostFix = getFilePostFix(); + destDir = new File("../openwire-cpp/src/command"); + return super.run(); + } + + protected String getFilePostFix() { + return ".cpp"; + } + + /** + * Converts the Java type to a C++ type name + */ + public String toCppType(JClass type) { + String name = type.getSimpleName(); + if (name.equals("String")) { + return "p"; + } + else if (name.equals("Throwable") || name.equals("Exception")) { + return "BrokerError"; + } + else if (name.equals("ByteSequence")) { + return "void*"; + } + else if (name.equals("boolean")) { + return "bool"; + } + else if (name.endsWith("Id")) { + return "p<" + name + ">"; + } + else { + return name; + } + } + + /** + * Converts the Java type to a C++ default value + */ + public String toCppDefaultValue(JClass type) { + return "NULL"; + } +} diff --git a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java new file mode 100644 index 0000000000..2344aa7325 --- /dev/null +++ b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2005-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.openwire.tool; + + +/** + * + * @version $Revision$ + */ +public abstract class OpenWireCppHeadersScript extends OpenWireCppClassesScript { + + protected String getFilePostFix() { + return ".hpp"; + } + +} diff --git a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java index e579db26df..6cf8f43fd8 100755 --- a/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java +++ b/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java @@ -17,7 +17,6 @@ package org.apache.activemq.openwire.tool; import org.codehaus.gram.GramSupport; -import org.codehaus.jam.JAnnotation; import org.codehaus.jam.JAnnotationValue; import org.codehaus.jam.JClass; import org.codehaus.jam.JField; @@ -103,6 +102,8 @@ public abstract class OpenWireScript extends GramSupport { return name; } } + + public String getOpenWireOpCode(JClass aClass) { return annotationValue(aClass, "openwire:marshaller", "code", "0"); } diff --git a/activemq-core/src/gram/script/GenerateCSharpClasses.groovy b/activemq-core/src/gram/script/GenerateCSharpClasses.groovy index 06e62b2d40..50a2cc8687 100755 --- a/activemq-core/src/gram/script/GenerateCSharpClasses.groovy +++ b/activemq-core/src/gram/script/GenerateCSharpClasses.groovy @@ -17,21 +17,29 @@ import org.apache.activemq.openwire.tool.OpenWireCSharpClassesScript /** - * Generates the C# marshalling code for the Open Wire Format + * Generates the C# commands for the Open Wire Format * * @version $Revision$ */ class GenerateCSharpClasses extends OpenWireCSharpClassesScript { void generateFile(PrintWriter 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 << """/* +* Copyright 2006 The Apache Software Foundation or its licensors, as +* applicable. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ using System; using System.Collections; @@ -41,21 +49,27 @@ using OpenWire.Client.Core; namespace OpenWire.Client.Commands { + // + // 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-core module + // public class ${jclass.simpleName} : $baseClass { - public const byte ID_${jclass.simpleName} = ${getOpenWireOpCode(jclass)}; + public const byte ID_${jclass.simpleName} = ${getOpenWireOpCode(jclass)}; """ - for (property in properties) { - - def type = toCSharpType(property.type) - def name = decapitalize(property.simpleName) - out << """ $type $name; + for (property in properties) { + def type = toCSharpType(property.type) + def name = decapitalize(property.simpleName) + out << """ $type $name; """ - } - - out << """ + } + out << """ // TODO generate Equals method // TODO generate GetHashCode method diff --git a/activemq-core/src/gram/script/GenerateCppClasses.groovy b/activemq-core/src/gram/script/GenerateCppClasses.groovy new file mode 100755 index 0000000000..dcf4d838e5 --- /dev/null +++ b/activemq-core/src/gram/script/GenerateCppClasses.groovy @@ -0,0 +1,92 @@ +/** + * + * Copyright 2005-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.apache.activemq.openwire.tool.OpenWireCppClassesScript + +/** + * Generates the C++ commands for the Open Wire Format + * + * @version $Revision$ + */ +class GenerateCppClasses extends OpenWireCppClassesScript { + + void generateFile(PrintWriter out) { + out << """/* +* Copyright 2006 The Apache Software Foundation or its licensors, as +* applicable. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "command/${className}.hpp" + +using namespace apache::activemq::client::command; + +/* + * + * Marshalling code for Open Wire Format for ${className} + * + * + * NOTE!: This file is autogenerated - do not modify! + * if you need to make a change, please see the Groovy scripts in the + * activemq-core module + * + */ +${className}::${className}() +{""" + for (property in properties) { + def value = toCppDefaultValue(property.type) + def propertyName = property.simpleName + def parameterName = decapitalize(propertyName) + out << """ + this->${parameterName} = ${value} ;""" + } + out << """ +} + +${className}::~${className}() +{ +} +""" + for (property in properties) { + def type = toCppType(property.type) + def propertyName = property.simpleName + def parameterName = decapitalize(propertyName) + out << """ + +${type} ${className}::get${propertyName}() +{ + return ${parameterName} ; +} + +void ${className}::set${propertyName}(${type} ${parameterName}) +{ + this->${parameterName} = ${parameterName} ; +} +""" + + } + } +} \ No newline at end of file diff --git a/activemq-core/src/gram/script/GenerateCppHeaders.groovy b/activemq-core/src/gram/script/GenerateCppHeaders.groovy new file mode 100755 index 0000000000..8b020b8cd0 --- /dev/null +++ b/activemq-core/src/gram/script/GenerateCppHeaders.groovy @@ -0,0 +1,121 @@ +/** + * + * Copyright 2005-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.apache.activemq.openwire.tool.OpenWireCppHeadersScript + +/** + * Generates the C++ commands for the Open Wire Format + * + * @version $Revision$ + */ +class GenerateCppHeaders extends OpenWireCppHeadersScript { + + void generateFile(PrintWriter out) { + out << """/* +* Copyright 2006 The Apache Software Foundation or its licensors, as +* applicable. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ${className}_hpp_ +#define ${className}_hpp_ + +#include + +/* we could cut this down - for now include all possible headers */ +#include "command/BaseCommand.hpp" +#include "command/BrokerId.hpp" +#include "command/ConnectionId.hpp" +#include "command/ConsumerId.hpp" +#include "command/ProducerId.hpp" +#include "command/SessionId.hpp" + +#include "command/${baseClass}.hpp" +#include "util/ifr/p" + +namespace apache +{ + namespace activemq + { + namespace client + { + namespace command + { + using namespace ifr; + using namespace apache::activemq::client; + +/* + * + * Marshalling code for Open Wire Format for ${className} + * + * + * NOTE!: This file is autogenerated - do not modify! + * if you need to make a change, please see the Groovy scripts in the + * activemq-core module + * + */ +class ${className} : public ${baseClass} +{ +private: +""" + for (property in properties) { + def type = toCppType(property.type) + def name = decapitalize(property.simpleName) + out << """ $type $name ; +""" + } + out << """ +public: + const static int TYPE = ${getOpenWireOpCode(jclass)}; + +public: + ${className}() ; + virtual ~${className}() ; + +""" + for (property in properties) { + def type = toCppType(property.type) + def propertyName = property.simpleName + def parameterName = decapitalize(propertyName) + out << """ + virtual ${type} get${propertyName}() ; + virtual void set${propertyName}(${type} ${parameterName}) ; +""" + } + out << """ + +} ; + +/* namespace */ + } + } + } +} + +#endif /*${className}_hpp_*/ +""" + } +} \ No newline at end of file