Modified: activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java?view=diff&rev=565003&r1=565002&r2=565003
==============================================================================
--- activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java (original)
+++ activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java Sat Aug 11 22:27:21 2007
@@ -28,45 +28,44 @@
import org.codehaus.jam.JProperty;
/**
- *
* @version $Revision: 383749 $
*/
public class CSourcesGenerator extends CHeadersGenerator {
- public Object run() {
- filePostFix = ".c";
- if (destFile == null) {
- destFile = new File(targetDir + "/ow_commands_v" + getOpenwireVersion() + ".c");
- }
- return super.run();
- }
-
- protected List sort(List source) {
- return source;
- }
-
- protected void generateSetup(PrintWriter out) {
- generateLicence(out);
- out.println("");
- out.println("/*****************************************************************************************");
- out.println(" * ");
- out.println(" * NOTE!: This file is auto generated - do not modify!");
- out.println(" * if you need to make a change, please see the modify the groovy scripts in the");
- out.println(" * under src/gram/script and then use maven openwire:generate to regenerate ");
- out.println(" * this file.");
- out.println(" * ");
- out.println(" *****************************************************************************************/");
- out.println("");
- out.println("");
- out.println("#include \"ow_commands_v"+openwireVersion+".h\"");
- out.println("");
- out.println("#define SUCCESS_CHECK( f ) { apr_status_t rc=f; if(rc!=APR_SUCCESS) return rc; }");
- out.println("");
- }
-
- protected void generateFile(PrintWriter out) throws Exception {
-
- ArrayList properties = new ArrayList();
+ public Object run() {
+ filePostFix = ".c";
+ if (destFile == null) {
+ destFile = new File(targetDir + "/ow_commands_v" + getOpenwireVersion() + ".c");
+ }
+ return super.run();
+ }
+
+ protected List sort(List source) {
+ return source;
+ }
+
+ protected void generateSetup(PrintWriter out) {
+ generateLicence(out);
+ out.println("");
+ out.println("/*****************************************************************************************");
+ out.println(" * ");
+ out.println(" * NOTE!: This file is auto generated - do not modify!");
+ out.println(" * if you need to make a change, please see the modify the groovy scripts in the");
+ out.println(" * under src/gram/script and then use maven openwire:generate to regenerate ");
+ out.println(" * this file.");
+ out.println(" * ");
+ out.println(" *****************************************************************************************/");
+ out.println("");
+ out.println("");
+ out.println("#include \"ow_commands_v" + openwireVersion + ".h\"");
+ out.println("");
+ out.println("#define SUCCESS_CHECK( f ) { apr_status_t rc=f; if(rc!=APR_SUCCESS) return rc; }");
+ out.println("");
+ }
+
+ protected void generateFile(PrintWriter out) throws Exception {
+
+ ArrayList<JProperty> properties = new ArrayList<JProperty>();
jclass.getDeclaredProperties();
for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
JProperty p = jclass.getDeclaredProperties()[i];
@@ -74,307 +73,306 @@
properties.add(p);
}
}
-
- String name = jclass.getSimpleName();
- String type = ("ow_"+name).toUpperCase()+"_TYPE";
- String baseName = "DataStructure";
- JClass superclass = jclass.getSuperclass();
- while( superclass.getSuperclass() != null ) {
- if( sortedClasses.contains(superclass) ) {
- baseName = superclass.getSimpleName();
- break;
- } else {
- superclass = superclass.getSuperclass();
- }
- }
-
-out.println("ow_boolean ow_is_a_"+name+"(ow_DataStructure *object) {");
-out.println(" if( object == 0 )");
-out.println(" return 0;");
-out.println(" ");
-out.println(" switch(object->structType) {");
-
- for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
- JClass sub = (JClass) iterator.next();
- String subtype = "OW_"+sub.getSimpleName().toUpperCase()+"_TYPE";
- if( jclass.isAssignableFrom(sub) && !isAbstract(sub) ) {
-out.println("");
-out.println(" case "+subtype+":");
- }
- }
-out.println("");
-out.println(" return 1;");
-out.println(" }");
-out.println(" return 0;");
-out.println("}");
-
- if( !isAbstract(jclass) ) {
-out.println("");
-out.println("");
-out.println("ow_"+name+" *ow_"+name+"_create(apr_pool_t *pool) ");
-out.println("{");
-out.println(" ow_"+name+" *value = apr_pcalloc(pool,sizeof(ow_"+name+"));");
-out.println(" if( value!=0 ) {");
-out.println(" ((ow_DataStructure*)value)->structType = "+type+";");
-out.println(" }");
-out.println(" return value;");
-out.println("}");
- }
-
-out.println("");
-out.println("");
-out.println("apr_status_t ow_marshal1_"+name+"(ow_bit_buffer *buffer, ow_"+name+" *object)");
-out.println("{");
-out.println(" ow_marshal1_"+baseName+"(buffer, (ow_"+baseName+"*)object);");
-
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- String propname = toPropertyCase(property.getSimpleName());
- boolean cached = isCachedProperty(property);
- JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
- JAnnotationValue size = annotation.getValue("size");
-
- type = property.getType().getQualifiedName();
- if( type.equals("boolean")) {
-out.println(" ow_bit_buffer_append(buffer, object->"+propname+");");
- } else if( type.equals("byte")) {
- } else if( type.equals("char")) {
- } else if( type.equals("short")) {
- } else if( type.equals("int")) {
- } else if( type.equals("long")) {
-out.println(" ow_marshal1_long(buffer, object->"+propname+");");
- } else if( type.equals("byte[]")) {
- if( size ==null ) {
-out.println(" ow_bit_buffer_append(buffer, object->"+propname+"!=0 );");
- }
- } else if( type.equals("org.apache.activeio.packet.ByteSequence")) {
- if( size ==null ) {
-out.println(" ow_bit_buffer_append(buffer, object->"+propname+"!=0 );");
- }
- } else if( type.equals("java.lang.String")) {
-out.println(" ow_marshal1_string(buffer, object->"+propname+");");
- } else {
- if( property.getType().isArrayType() ) {
- if( size!=null ) {
-out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
- } else {
-out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->"+propname+"));");
- }
- } else if( isThrowable(property.getType()) ) {
-out.println(" SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->"+propname+"));");
- } else {
- if( cached ) {
-out.println(" SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->"+propname+"));");
- } else {
-out.println(" SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->"+propname+"));");
- }
- }
- }
-out.println("");
- }
-
-
-out.println(" ");
-out.println(" return APR_SUCCESS;");
-out.println("}");
-out.println("apr_status_t ow_marshal2_"+name+"(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_"+name+" *object)");
-out.println("{");
-out.println(" ow_marshal2_"+baseName+"(buffer, bitbuffer, (ow_"+baseName+"*)object); ");
-
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
- JAnnotationValue size = annotation.getValue("size");
- Object propname = toPropertyCase(property.getSimpleName());
- boolean cached = isCachedProperty(property);
-
- type = property.getType().getQualifiedName();
- if( type.equals("boolean") ) {
-out.println(" ow_bit_buffer_read(bitbuffer);");
- } else if( type.equals("byte") ) {
-out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
- } else if( type.equals("char") ) {
-out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
- } else if( type.equals("short") ) {
-out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
- } else if( type.equals("int") ) {
-out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
- } else if( type.equals("long") ) {
-out.println(" SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->"+propname+"));");
- } else if( type.equals("byte[]") ) {
- if( size!=null ) {
-out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
- } else {
-out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->"+propname+"));");
- }
- } else if( type.equals("org.apache.activeio.packet.ByteSequence") ) {
- if( size!=null ) {
-out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
- } else {
-out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->"+propname+"));");
- }
- } else if( type.equals("java.lang.String") ) {
-out.println(" SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->"+propname+"));");
- } else {
- if( property.getType().isArrayType() ) {
- if( size!=null ) {
-out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->"+propname+", "+size.asInt()+"));");
- } else {
-out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->"+propname+"));");
- }
- } else if( isThrowable(property.getType()) ) {
-out.println(" SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->"+propname+"));");
- } else {
- if( cached ) {
-out.println(" SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->"+propname+"));");
- } else {
-out.println(" SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->"+propname+"));");
- }
- }
- }
-out.println("");
- }
-
-out.println(" ");
-out.println(" return APR_SUCCESS;");
-out.println("}");
-out.println("");
-out.println("apr_status_t ow_unmarshal_"+name+"(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_"+name+" *object, apr_pool_t *pool)");
-out.println("{");
-out.println(" ow_unmarshal_"+baseName+"(buffer, bitbuffer, (ow_"+baseName+"*)object, pool); ");
-
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
- JAnnotationValue size = annotation.getValue("size");
- String propname = toPropertyCase(property.getSimpleName());
- boolean cached = isCachedProperty(property);
-
- type = property.getType().getQualifiedName();
-
- if( type.equals("boolean") ) {
-out.println(" object->"+propname+" = ow_bit_buffer_read(bitbuffer);");
- } else if( type.equals("byte") ) {
-out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
- } else if( type.equals("char") ) {
-out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
- } else if( type.equals("short") ) {
-out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
- } else if( type.equals("int") ) {
-out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
- } else if( type.equals("long") ) {
-out.println(" SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->"+propname+", pool));");
- } else if( type.equals("byte[]") ) {
- if( size!=null ) {
-out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->"+propname+", "+size.asInt()+", pool));");
- } else {
-out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->"+propname+", pool));");
- }
- } else if( type.equals("org.apache.activeio.packet.ByteSequence") ) {
- if( size!=null ) {
-out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->"+propname+", "+size.asInt()+", pool));");
- } else {
-out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->"+propname+", pool));");
- }
- } else if( type.equals("java.lang.String") ) {
-out.println(" SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->"+propname+", pool));");
- } else {
- if( property.getType().isArrayType() ) {
- if( size!=null ) {
-out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->"+propname+", "+size.asInt()+", pool));");
- } else {
-out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->"+propname+", pool));");
- }
- } else if( isThrowable(property.getType()) ) {
-out.println(" SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->"+propname+", pool));");
- } else {
- if( cached ) {
-out.println(" SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->"+propname+", pool));");
- } else {
-out.println(" SUCCESS_CHECK(ow_unmarshal_nested_object(buffer, bitbuffer, (ow_DataStructure**)&object->"+propname+", pool));");
- }
- }
- }
-out.println("");
- }
-
-out.println(" ");
-out.println(" return APR_SUCCESS;");
-out.println("}");
- }
-
- protected void generateTearDown(PrintWriter out) {
-out.println("");
-out.println("ow_DataStructure *ow_create_object(ow_byte type, apr_pool_t *pool)");
-out.println("{");
-out.println(" switch( type ) {");
- for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
- JClass jclass = (JClass) iterator.next();
+
+ String name = jclass.getSimpleName();
+ String type = ("ow_" + name).toUpperCase() + "_TYPE";
+ String baseName = "DataStructure";
+ JClass superclass = jclass.getSuperclass();
+ while (superclass.getSuperclass() != null) {
+ if (sortedClasses.contains(superclass)) {
+ baseName = superclass.getSimpleName();
+ break;
+ } else {
+ superclass = superclass.getSuperclass();
+ }
+ }
+
+ out.println("ow_boolean ow_is_a_" + name + "(ow_DataStructure *object) {");
+ out.println(" if( object == 0 )");
+ out.println(" return 0;");
+ out.println(" ");
+ out.println(" switch(object->structType) {");
+
+ for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+ JClass sub = (JClass)iterator.next();
+ String subtype = "OW_" + sub.getSimpleName().toUpperCase() + "_TYPE";
+ if (jclass.isAssignableFrom(sub) && !isAbstract(sub)) {
+ out.println("");
+ out.println(" case " + subtype + ":");
+ }
+ }
+ out.println("");
+ out.println(" return 1;");
+ out.println(" }");
+ out.println(" return 0;");
+ out.println("}");
+
+ if (!isAbstract(jclass)) {
+ out.println("");
+ out.println("");
+ out.println("ow_" + name + " *ow_" + name + "_create(apr_pool_t *pool) ");
+ out.println("{");
+ out.println(" ow_" + name + " *value = apr_pcalloc(pool,sizeof(ow_" + name + "));");
+ out.println(" if( value!=0 ) {");
+ out.println(" ((ow_DataStructure*)value)->structType = " + type + ";");
+ out.println(" }");
+ out.println(" return value;");
+ out.println("}");
+ }
+
+ out.println("");
+ out.println("");
+ out.println("apr_status_t ow_marshal1_" + name + "(ow_bit_buffer *buffer, ow_" + name + " *object)");
+ out.println("{");
+ out.println(" ow_marshal1_" + baseName + "(buffer, (ow_" + baseName + "*)object);");
+
+ for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = iter.next();
+ String propname = toPropertyCase(property.getSimpleName());
+ boolean cached = isCachedProperty(property);
+ JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+
+ type = property.getType().getQualifiedName();
+ if (type.equals("boolean")) {
+ out.println(" ow_bit_buffer_append(buffer, object->" + propname + ");");
+ } else if (type.equals("byte")) {
+ } else if (type.equals("char")) {
+ } else if (type.equals("short")) {
+ } else if (type.equals("int")) {
+ } else if (type.equals("long")) {
+ out.println(" ow_marshal1_long(buffer, object->" + propname + ");");
+ } else if (type.equals("byte[]")) {
+ if (size == null) {
+ out.println(" ow_bit_buffer_append(buffer, object->" + propname + "!=0 );");
+ }
+ } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
+ if (size == null) {
+ out.println(" ow_bit_buffer_append(buffer, object->" + propname + "!=0 );");
+ }
+ } else if (type.equals("java.lang.String")) {
+ out.println(" ow_marshal1_string(buffer, object->" + propname + ");");
+ } else {
+ if (property.getType().isArrayType()) {
+ if (size != null) {
+ out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->" + propname + "));");
+ }
+ } else if (isThrowable(property.getType())) {
+ out.println(" SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->" + propname + "));");
+ } else {
+ if (cached) {
+ out.println(" SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->" + propname + "));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->" + propname + "));");
+ }
+ }
+ }
+ out.println("");
+ }
+
+ out.println(" ");
+ out.println(" return APR_SUCCESS;");
+ out.println("}");
+ out.println("apr_status_t ow_marshal2_" + name + "(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_" + name + " *object)");
+ out.println("{");
+ out.println(" ow_marshal2_" + baseName + "(buffer, bitbuffer, (ow_" + baseName + "*)object); ");
+
+ for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = iter.next();
+ JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+ Object propname = toPropertyCase(property.getSimpleName());
+ boolean cached = isCachedProperty(property);
+
+ type = property.getType().getQualifiedName();
+ if (type.equals("boolean")) {
+ out.println(" ow_bit_buffer_read(bitbuffer);");
+ } else if (type.equals("byte")) {
+ out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
+ } else if (type.equals("char")) {
+ out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
+ } else if (type.equals("short")) {
+ out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
+ } else if (type.equals("int")) {
+ out.println(" SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
+ } else if (type.equals("long")) {
+ out.println(" SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->" + propname + "));");
+ } else if (type.equals("byte[]")) {
+ if (size != null) {
+ out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->" + propname + "));");
+ }
+ } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
+ if (size != null) {
+ out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->" + propname + "));");
+ }
+ } else if (type.equals("java.lang.String")) {
+ out.println(" SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->" + propname + "));");
+ } else {
+ if (property.getType().isArrayType()) {
+ if (size != null) {
+ out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->" + propname + ", " + size.asInt() + "));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->" + propname + "));");
+ }
+ } else if (isThrowable(property.getType())) {
+ out.println(" SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->" + propname + "));");
+ } else {
+ if (cached) {
+ out.println(" SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->" + propname + "));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->" + propname + "));");
+ }
+ }
+ }
+ out.println("");
+ }
+
+ out.println(" ");
+ out.println(" return APR_SUCCESS;");
+ out.println("}");
+ out.println("");
+ out.println("apr_status_t ow_unmarshal_" + name + "(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_" + name + " *object, apr_pool_t *pool)");
+ out.println("{");
+ out.println(" ow_unmarshal_" + baseName + "(buffer, bitbuffer, (ow_" + baseName + "*)object, pool); ");
+
+ for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = iter.next();
+ JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+ String propname = toPropertyCase(property.getSimpleName());
+ boolean cached = isCachedProperty(property);
+
+ type = property.getType().getQualifiedName();
+
+ if (type.equals("boolean")) {
+ out.println(" object->" + propname + " = ow_bit_buffer_read(bitbuffer);");
+ } else if (type.equals("byte")) {
+ out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
+ } else if (type.equals("char")) {
+ out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
+ } else if (type.equals("short")) {
+ out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
+ } else if (type.equals("int")) {
+ out.println(" SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
+ } else if (type.equals("long")) {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->" + propname + ", pool));");
+ } else if (type.equals("byte[]")) {
+ if (size != null) {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->" + propname + ", " + size.asInt() + ", pool));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->" + propname + ", pool));");
+ }
+ } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
+ if (size != null) {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->" + propname + ", " + size.asInt() + ", pool));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->" + propname + ", pool));");
+ }
+ } else if (type.equals("java.lang.String")) {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->" + propname + ", pool));");
+ } else {
+ if (property.getType().isArrayType()) {
+ if (size != null) {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->" + propname + ", " + size.asInt() + ", pool));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->" + propname + ", pool));");
+ }
+ } else if (isThrowable(property.getType())) {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->" + propname + ", pool));");
+ } else {
+ if (cached) {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->" + propname + ", pool));");
+ } else {
+ out.println(" SUCCESS_CHECK(ow_unmarshal_nested_object(buffer, bitbuffer, (ow_DataStructure**)&object->" + propname + ", pool));");
+ }
+ }
+ }
+ out.println("");
+ }
+
+ out.println(" ");
+ out.println(" return APR_SUCCESS;");
+ out.println("}");
+ }
+
+ protected void generateTearDown(PrintWriter out) {
+ out.println("");
+ out.println("ow_DataStructure *ow_create_object(ow_byte type, apr_pool_t *pool)");
+ out.println("{");
+ out.println(" switch( type ) {");
+ for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+ JClass jclass = (JClass)iterator.next();
String name = jclass.getSimpleName();
- String type = ("ow_"+name).toUpperCase()+"_TYPE";
- if( !isAbstract(jclass) ) {
-out.println(" case "+type+": return (ow_DataStructure *)ow_"+name+"_create(pool);");
+ String type = ("ow_" + name).toUpperCase() + "_TYPE";
+ if (!isAbstract(jclass)) {
+ out.println(" case " + type + ": return (ow_DataStructure *)ow_" + name + "_create(pool);");
}
- }
-
-out.println("");
-out.println(" }");
-out.println(" return 0;");
-out.println("}");
-out.println("");
-out.println("apr_status_t ow_marshal1_object(ow_bit_buffer *buffer, ow_DataStructure *object)");
-out.println("{");
-out.println(" switch( object->structType ) {");
+ }
+
+ out.println("");
+ out.println(" }");
+ out.println(" return 0;");
+ out.println("}");
+ out.println("");
+ out.println("apr_status_t ow_marshal1_object(ow_bit_buffer *buffer, ow_DataStructure *object)");
+ out.println("{");
+ out.println(" switch( object->structType ) {");
- for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
- JClass jclass = (JClass) iterator.next();
+ for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+ JClass jclass = (JClass)iterator.next();
String name = jclass.getSimpleName();
- String type = ("ow_"+name).toUpperCase()+"_TYPE";
- if( !isAbstract(jclass) ) {
-out.println(" case "+type+": return ow_marshal1_"+name+"(buffer, (ow_"+name+"*)object);");
+ String type = ("ow_" + name).toUpperCase() + "_TYPE";
+ if (!isAbstract(jclass)) {
+ out.println(" case " + type + ": return ow_marshal1_" + name + "(buffer, (ow_" + name + "*)object);");
}
- }
-
-out.println("");
-out.println(" }");
-out.println(" return APR_EGENERAL;");
-out.println("}");
-out.println("");
-out.println("apr_status_t ow_marshal2_object(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object)");
-out.println("{");
-out.println(" switch( object->structType ) {");
+ }
+
+ out.println("");
+ out.println(" }");
+ out.println(" return APR_EGENERAL;");
+ out.println("}");
+ out.println("");
+ out.println("apr_status_t ow_marshal2_object(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object)");
+ out.println("{");
+ out.println(" switch( object->structType ) {");
- for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
- JClass jclass = (JClass) iterator.next();
+ for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+ JClass jclass = (JClass)iterator.next();
String name = jclass.getSimpleName();
- String type = ("ow_"+name).toUpperCase()+"_TYPE";
- if( !isAbstract(jclass) ) {
-out.println(" case "+type+": return ow_marshal2_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object);");
+ String type = ("ow_" + name).toUpperCase() + "_TYPE";
+ if (!isAbstract(jclass)) {
+ out.println(" case " + type + ": return ow_marshal2_" + name + "(buffer, bitbuffer, (ow_" + name + "*)object);");
}
- }
+ }
-out.println("");
-out.println(" }");
-out.println(" return APR_EGENERAL;");
-out.println("}");
-out.println("");
-out.println("apr_status_t ow_unmarshal_object(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object, apr_pool_t *pool)");
-out.println("{");
-out.println(" switch( object->structType ) {");
+ out.println("");
+ out.println(" }");
+ out.println(" return APR_EGENERAL;");
+ out.println("}");
+ out.println("");
+ out.println("apr_status_t ow_unmarshal_object(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object, apr_pool_t *pool)");
+ out.println("{");
+ out.println(" switch( object->structType ) {");
- for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
- JClass jclass = (JClass) iterator.next();
+ for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+ JClass jclass = (JClass)iterator.next();
String name = jclass.getSimpleName();
- String type = ("ow_"+name).toUpperCase()+"_TYPE";
- if( !isAbstract(jclass) ) {
-out.println(" case "+type+": return ow_unmarshal_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object, pool);");
+ String type = ("ow_" + name).toUpperCase() + "_TYPE";
+ if (!isAbstract(jclass)) {
+ out.println(" case " + type + ": return ow_unmarshal_" + name + "(buffer, bitbuffer, (ow_" + name + "*)object, pool);");
}
- }
+ }
+
+ out.println("");
+ out.println(" }");
+ out.println(" return APR_EGENERAL;");
+ out.println("}");
-out.println("");
-out.println(" }");
-out.println(" return APR_EGENERAL;");
-out.println("}");
-
- }
+ }
}
Modified: activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java?view=diff&rev=565003&r1=565002&r2=565003
==============================================================================
--- activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java (original)
+++ activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java Sat Aug 11 22:27:21 2007
@@ -1,5 +1,4 @@
-/*
- *
+/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -26,17 +25,16 @@
import org.codehaus.jam.JProperty;
/**
- *
* @version $Revision: 409828 $
*/
public class CppClassesGenerator extends MultiSourceGenerator {
- protected String targetDir="./src/main/cpp";
+ protected String targetDir = "./src/main/cpp";
public Object run() {
filePostFix = getFilePostFix();
if (destDir == null) {
- destDir = new File(targetDir+"/activemq/command");
+ destDir = new File(targetDir + "/activemq/command");
}
return super.run();
}
@@ -52,38 +50,29 @@
String name = type.getSimpleName();
if (name.equals("String")) {
return "p<string>";
- }
- else if (type.isArrayType()) {
- if( name.equals("byte[]") )
- name = "char[]" ;
- else if( name.equals("DataStructure[]") )
- name = "IDataStructure[]" ;
-
- return "array<" + name.substring(0, name.length()-2) + ">";
- }
- else if (name.equals("Throwable") || name.equals("Exception")) {
+ } else if (type.isArrayType()) {
+ if (name.equals("byte[]")) {
+ name = "char[]";
+ } else if (name.equals("DataStructure[]")) {
+ name = "IDataStructure[]";
+ }
+ return "array<" + name.substring(0, name.length() - 2) + ">";
+ } else if (name.equals("Throwable") || name.equals("Exception")) {
return "p<BrokerError>";
- }
- else if (name.equals("ByteSequence")) {
+ } else if (name.equals("ByteSequence")) {
return "array<char>";
- }
- else if (name.equals("boolean")) {
+ } else if (name.equals("boolean")) {
return "bool";
- }
- else if (name.equals("long")) {
+ } else if (name.equals("long")) {
return "long long";
- }
- else if (name.equals("byte")) {
+ } else if (name.equals("byte")) {
return "char";
- }
- else if( name.equals("Command") || name.equals("DataStructure") ) {
- return "p<I" + name + ">" ;
- }
- else if( !type.isPrimitiveType() ) {
- return "p<" + name + ">" ;
- }
- else {
- return name ;
+ } else if (name.equals("Command") || name.equals("DataStructure")) {
+ return "p<I" + name + ">";
+ } else if (!type.isPrimitiveType()) {
+ return "p<" + name + ">";
+ } else {
+ return name;
}
}
@@ -93,108 +82,84 @@
public String toCppDefaultValue(JClass type) {
String name = type.getSimpleName();
- if ( name.equals("boolean") ) {
+ if (name.equals("boolean")) {
return "false";
- }
- else if (!type.isPrimitiveType()) {
+ } else if (!type.isPrimitiveType()) {
return "NULL";
- }
- else {
+ } else {
return "0";
}
}
/**
- * Converts the Java type to the name of the C++ marshal method
- * to be used
+ * Converts the Java type to the name of the C++ marshal method to be used
*/
public String toMarshalMethodName(JClass type) {
String name = type.getSimpleName();
if (name.equals("String")) {
return "marshalString";
- }
- else if (type.isArrayType()) {
- if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
- return "marshalByteArray" ;
- else
- return "marshalObjectArray" ;
- }
- else if ( name.equals("ByteSequence") ) {
+ } else if (type.isArrayType()) {
+ if (type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]")) {
+ return "marshalByteArray";
+ } else {
+ return "marshalObjectArray";
+ }
+ } else if (name.equals("ByteSequence")) {
return "marshalByteArray";
- }
- else if (name.equals("short") ) {
+ } else if (name.equals("short")) {
return "marshalShort";
- }
- else if (name.equals("int") ) {
+ } else if (name.equals("int")) {
return "marshalInt";
- }
- else if (name.equals("long") ) {
+ } else if (name.equals("long")) {
return "marshalLong";
- }
- else if (name.equals("byte")) {
+ } else if (name.equals("byte")) {
return "marshalByte";
- }
- else if (name.equals("double")) {
+ } else if (name.equals("double")) {
return "marshalDouble";
- }
- else if (name.equals("float")) {
+ } else if (name.equals("float")) {
return "marshalFloat";
- }
- else if (name.equals("boolean")) {
+ } else if (name.equals("boolean")) {
return "marshalBoolean";
- }
- else if( !type.isPrimitiveType() ) {
- return "marshalObject" ;
- }
- else {
- return name ;
+ } else if (!type.isPrimitiveType()) {
+ return "marshalObject";
+ } else {
+ return name;
}
}
/**
- * Converts the Java type to the name of the C++ unmarshal method
- * to be used
+ * Converts the Java type to the name of the C++ unmarshal method to be used
*/
public String toUnmarshalMethodName(JClass type) {
String name = type.getSimpleName();
if (name.equals("String")) {
return "unmarshalString";
- }
- else if (type.isArrayType()) {
- if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
- return "unmarshalByteArray" ;
- else
- return "unmarshalObjectArray" ;
- }
- else if ( name.equals("ByteSequence") ) {
+ } else if (type.isArrayType()) {
+ if (type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]")) {
+ return "unmarshalByteArray";
+ } else {
+ return "unmarshalObjectArray";
+ }
+ } else if (name.equals("ByteSequence")) {
return "unmarshalByteArray";
- }
- else if (name.equals("short") ) {
+ } else if (name.equals("short")) {
return "unmarshalShort";
- }
- else if (name.equals("int") ) {
+ } else if (name.equals("int")) {
return "unmarshalInt";
- }
- else if (name.equals("long") ) {
+ } else if (name.equals("long")) {
return "unmarshalLong";
- }
- else if (name.equals("byte")) {
+ } else if (name.equals("byte")) {
return "unmarshalByte";
- }
- else if (name.equals("double")) {
+ } else if (name.equals("double")) {
return "unmarshalDouble";
- }
- else if (name.equals("float")) {
+ } else if (name.equals("float")) {
return "unmarshalFloat";
- }
- else if (name.equals("boolean")) {
+ } else if (name.equals("boolean")) {
return "unmarshalBoolean";
- }
- else if( !type.isPrimitiveType() ) {
- return "unmarshalObject" ;
- }
- else {
- return name ;
+ } else if (!type.isPrimitiveType()) {
+ return "unmarshalObject";
+ } else {
+ return name;
}
}
@@ -202,128 +167,125 @@
* Converts the Java type to a C++ pointer cast
*/
public String toUnmarshalCast(JClass type) {
- String name = toCppType(type) ;
+ String name = toCppType(type);
+
+ if (name.startsWith("p<")) {
+ return "p_cast<" + name.substring(2);
+ } else if (name.startsWith("array<") && (type.isArrayType() && !type.getArrayComponentType().isPrimitiveType()) && !type.getSimpleName().equals("ByteSequence")) {
+ return "array_cast<" + name.substring(6);
+ } else {
+ return "";
+ }
+ }
+
+ protected void generateLicence(PrintWriter out) {
+ out.println("/**");
+ out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+ out.println(" * contributor license agreements. See the NOTICE file distributed with");
+ out.println(" * this work for additional information regarding copyright ownership.");
+ out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+ out.println(" * (the \"License\"); you may not use this file except in compliance with");
+ out.println(" * the License. You may obtain a copy of the License at");
+ out.println(" *");
+ out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+ out.println(" *");
+ out.println(" * Unless required by applicable law or agreed to in writing, software");
+ out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+ out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+ out.println(" * See the License for the specific language governing permissions and");
+ out.println(" * limitations under the License.");
+ out.println(" */");
+ }
+
+ protected void generateFile(PrintWriter out) throws Exception {
+ generateLicence(out);
+ out.println("#include \"activemq/command/" + className + ".hpp\"");
+ out.println("");
+ out.println("using namespace apache::activemq::command;");
+ out.println("");
+ out.println("/*");
+ out.println(" *");
+ out.println(" * Command and marshalling code for OpenWire format for " + className + "");
+ out.println(" *");
+ out.println(" *");
+ out.println(" * NOTE!: This file is autogenerated - do not modify!");
+ out.println(" * if you need to make a change, please see the Groovy scripts in the");
+ out.println(" * activemq-core module");
+ out.println(" *");
+ out.println(" */");
+ out.println("" + className + "::" + className + "()");
+ out.println("{");
+
+ List properties = getProperties();
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty)iter.next();
+ String value = toCppDefaultValue(property.getType());
+ String propertyName = property.getSimpleName();
+ String parameterName = decapitalize(propertyName);
+ out.println(" this->" + parameterName + " = " + value + " ;");
+ }
+ out.println("}");
+ out.println("");
+ out.println("" + className + "::~" + className + "()");
+ out.println("{");
+ out.println("}");
+ out.println("");
+ out.println("unsigned char " + className + "::getDataStructureType()");
+ out.println("{");
+ out.println(" return " + className + "::TYPE ; ");
+ out.println("}");
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty)iter.next();
+ String type = toCppType(property.getType());
+ String propertyName = property.getSimpleName();
+ String parameterName = decapitalize(propertyName);
+ out.println("");
+ out.println(" ");
+ out.println("" + type + " " + className + "::get" + propertyName + "()");
+ out.println("{");
+ out.println(" return " + parameterName + " ;");
+ out.println("}");
+ out.println("");
+ out.println("void " + className + "::set" + propertyName + "(" + type + " " + parameterName + ")");
+ out.println("{");
+ out.println(" this->" + parameterName + " = " + parameterName + " ;");
+ out.println("}");
+ }
+ out.println("");
+ out.println("int " + className + "::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)");
+ out.println("{");
+ out.println(" int size = 0 ;");
+ out.println("");
+ out.println(" size += " + baseClass + "::marshal(marshaller, mode, ostream) ; ");
+
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty)iter.next();
+ String marshalMethod = toMarshalMethodName(property.getType());
+ String propertyName = decapitalize(property.getSimpleName());
+ out.println(" size += marshaller->" + marshalMethod + "(" + propertyName + ", mode, ostream) ; ");
+ }
+ out.println(" return size ;");
+ out.println("}");
+ out.println("");
+ out.println("void " + className + "::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)");
+ out.println("{");
+ out.println(" " + baseClass + "::unmarshal(marshaller, mode, istream) ; ");
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty)iter.next();
+ String cast = toUnmarshalCast(property.getType());
+ String unmarshalMethod = toUnmarshalMethodName(property.getType());
+ String propertyName = decapitalize(property.getSimpleName());
+ out.println(" " + propertyName + " = " + cast + "(marshaller->" + unmarshalMethod + "(mode, istream)) ; ");
+ }
+ out.println("}");
+ }
+
+ public String getTargetDir() {
+ return targetDir;
+ }
+
+ public void setTargetDir(String targetDir) {
+ this.targetDir = targetDir;
+ }
- if( name.startsWith("p<") )
- return "p_cast<" + name.substring(2) ;
- else if( name.startsWith("array<") &&
- (type.isArrayType() && !type.getArrayComponentType().isPrimitiveType()) &&
- !type.getSimpleName().equals("ByteSequence") )
- return "array_cast<" + name.substring(6) ;
- else
- return "" ;
- }
-
-
- protected void generateLicence(PrintWriter out) {
-out.println("/*");
-out.println(" *");
-out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
-out.println(" * contributor license agreements. See the NOTICE file distributed with");
-out.println(" * this work for additional information regarding copyright ownership.");
-out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
-out.println(" * (the \"License\"); you may not use this file except in compliance with");
-out.println(" * the License. You may obtain a copy of the License at");
-out.println(" *");
-out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
-out.println(" *");
-out.println(" * Unless required by applicable law or agreed to in writing, software");
-out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
-out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
-out.println(" * See the License for the specific language governing permissions and");
-out.println(" * limitations under the License.");
-out.println(" */");
- }
-
- protected void generateFile(PrintWriter out) throws Exception {
- generateLicence(out);
-out.println("#include \"activemq/command/"+className+".hpp\"");
-out.println("");
-out.println("using namespace apache::activemq::command;");
-out.println("");
-out.println("/*");
-out.println(" *");
-out.println(" * Command and marshalling code for OpenWire format for "+className+"");
-out.println(" *");
-out.println(" *");
-out.println(" * NOTE!: This file is autogenerated - do not modify!");
-out.println(" * if you need to make a change, please see the Groovy scripts in the");
-out.println(" * activemq-core module");
-out.println(" *");
-out.println(" */");
-out.println(""+className+"::"+className+"()");
-out.println("{");
-
- List properties = getProperties();
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- String value = toCppDefaultValue(property.getType());
- String propertyName = property.getSimpleName();
- String parameterName = decapitalize(propertyName);
-out.println(" this->"+parameterName+" = "+value+" ;");
- }
-out.println("}");
-out.println("");
-out.println(""+className+"::~"+className+"()");
-out.println("{");
-out.println("}");
-out.println("");
-out.println("unsigned char "+className+"::getDataStructureType()");
-out.println("{");
-out.println(" return "+className+"::TYPE ; ");
-out.println("}");
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- String type = toCppType(property.getType());
- String propertyName = property.getSimpleName();
- String parameterName = decapitalize(propertyName);
-out.println("");
-out.println(" ");
-out.println(""+type+" "+className+"::get"+propertyName+"()");
-out.println("{");
-out.println(" return "+parameterName+" ;");
-out.println("}");
-out.println("");
-out.println("void "+className+"::set"+propertyName+"("+type+" "+parameterName+")");
-out.println("{");
-out.println(" this->"+parameterName+" = "+parameterName+" ;");
-out.println("}");
- }
-out.println("");
-out.println("int "+className+"::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)");
-out.println("{");
-out.println(" int size = 0 ;");
-out.println("");
-out.println(" size += "+baseClass+"::marshal(marshaller, mode, ostream) ; ");
-
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- String marshalMethod = toMarshalMethodName(property.getType());
- String propertyName = decapitalize(property.getSimpleName());
-out.println(" size += marshaller->"+marshalMethod+"("+propertyName+", mode, ostream) ; ");
- }
-out.println(" return size ;");
-out.println("}");
-out.println("");
-out.println("void "+className+"::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)");
-out.println("{");
-out.println(" "+baseClass+"::unmarshal(marshaller, mode, istream) ; ");
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- String cast = toUnmarshalCast(property.getType());
- String unmarshalMethod = toUnmarshalMethodName(property.getType());
- String propertyName = decapitalize(property.getSimpleName());
-out.println(" "+propertyName+" = "+cast+"(marshaller->"+unmarshalMethod+"(mode, istream)) ; ");
- }
-out.println("}");
- }
-
- public String getTargetDir() {
- return targetDir;
- }
-
- public void setTargetDir(String targetDir) {
- this.targetDir = targetDir;
- }
-
}
Modified: activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java?view=diff&rev=565003&r1=565002&r2=565003
==============================================================================
--- activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java (original)
+++ activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java Sat Aug 11 22:27:21 2007
@@ -26,107 +26,107 @@
import org.codehaus.jam.JamServiceParams;
/**
- *
* @version $Revision: 384826 $
*/
public class CppGeneratorTask extends Task {
-
- int version = 2;
- File source = new File(".");
- File target = new File(".");
-
+
+ int version = 2;
+ File source = new File(".");
+ File target = new File(".");
+
public static void main(String[] args) {
-
+
Project project = new Project();
project.init();
- CppGeneratorTask generator = new CppGeneratorTask();
- generator.setProject(project);
-
- if( args.length > 0 ) {
- generator.version = Integer.parseInt(args[0]);
- }
-
- if( args.length > 1 ) {
- generator.source = new File(args[1]);
- }
-
- if( args.length > 2 ) {
- generator.target = new File(args[2]);
- }
-
- generator.execute();
- }
-
+ CppGeneratorTask generator = new CppGeneratorTask();
+ generator.setProject(project);
+
+ if (args.length > 0) {
+ generator.version = Integer.parseInt(args[0]);
+ }
+
+ if (args.length > 1) {
+ generator.source = new File(args[1]);
+ }
+
+ if (args.length > 2) {
+ generator.target = new File(args[2]);
+ }
+
+ generator.execute();
+ }
+
public void execute() throws BuildException {
try {
-
- String sourceDir = source+"/src/main/java";
-
+
+ String sourceDir = source + "/src/main/java";
+
System.out.println("Parsing source files in: " + sourceDir);
JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
- JamServiceParams params = jamServiceFactory.createServiceParams();
- File[] dirs = new File[]{new File(sourceDir)};
+ JamServiceParams params = jamServiceFactory.createServiceParams();
+ File[] dirs = new File[] {
+ new File(sourceDir)
+ };
params.includeSourcePattern(dirs, "**/*.java");
JamService jam = jamServiceFactory.createService(params);
{
- CppClassesGenerator script = new CppClassesGenerator();
- script.setJam(jam);
- script.setTargetDir(target+"/src/main/cpp");
- script.setOpenwireVersion(version);
- script.run();
+ CppClassesGenerator script = new CppClassesGenerator();
+ script.setJam(jam);
+ script.setTargetDir(target + "/src/main/cpp");
+ script.setOpenwireVersion(version);
+ script.run();
}
{
- CppHeadersGenerator script = new CppHeadersGenerator();
- script.setJam(jam);
- script.setTargetDir(target+"/src/main/cpp");
- script.setOpenwireVersion(version);
- script.run();
+ CppHeadersGenerator script = new CppHeadersGenerator();
+ script.setJam(jam);
+ script.setTargetDir(target + "/src/main/cpp");
+ script.setOpenwireVersion(version);
+ script.run();
}
{
- CppMarshallingHeadersGenerator script = new CppMarshallingHeadersGenerator();
- script.setJam(jam);
- script.setTargetDir(target+"/src");
- script.setOpenwireVersion(version);
- script.run();
+ CppMarshallingHeadersGenerator script = new CppMarshallingHeadersGenerator();
+ script.setJam(jam);
+ script.setTargetDir(target + "/src");
+ script.setOpenwireVersion(version);
+ script.run();
}
{
- CppMarshallingClassesGenerator script = new CppMarshallingClassesGenerator();
- script.setJam(jam);
- script.setTargetDir(target+"/src");
- script.setOpenwireVersion(version);
- script.run();
+ CppMarshallingClassesGenerator script = new CppMarshallingClassesGenerator();
+ script.setJam(jam);
+ script.setTargetDir(target + "/src");
+ script.setOpenwireVersion(version);
+ script.run();
}
-
-
+
} catch (Exception e) {
- throw new BuildException(e);
+ throw new BuildException(e);
}
}
- public int getVersion() {
- return version;
- }
-
- public void setVersion(int version) {
- this.version = version;
- }
-
- public File getSource() {
- return source;
- }
-
- public void setSource(File basedir) {
- this.source = basedir;
- }
-
- public File getTarget() {
- return target;
- }
-
- public void setTarget(File target) {
- this.target = target;
- }
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ public File getSource() {
+ return source;
+ }
+
+ public void setSource(File basedir) {
+ this.source = basedir;
+ }
+
+ public File getTarget() {
+ return target;
+ }
+
+ public void setTarget(File target) {
+ this.target = target;
+ }
}
Modified: activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java?view=diff&rev=565003&r1=565002&r2=565003
==============================================================================
--- activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java (original)
+++ activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java Sat Aug 11 22:27:21 2007
@@ -23,9 +23,7 @@
import org.codehaus.jam.JClass;
import org.codehaus.jam.JProperty;
-
/**
- *
* @version $Revision: 379734 $
*/
public class CppHeadersGenerator extends CppClassesGenerator {
@@ -33,117 +31,114 @@
protected String getFilePostFix() {
return ".hpp";
}
-
- protected void generateFile(PrintWriter out) {
- generateLicence(out);
-
-out.println("#ifndef ActiveMQ_"+className+"_hpp_");
-out.println("#define ActiveMQ_"+className+"_hpp_");
-out.println("");
-out.println("// Turn off warning message for ignored exception specification");
-out.println("#ifdef _MSC_VER");
-out.println("#pragma warning( disable : 4290 )");
-out.println("#endif");
-out.println("");
-out.println("#include <string>");
-out.println("#include \"activemq/command/"+baseClass+".hpp\"");
-
- List properties = getProperties();
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- if( !property.getType().isPrimitiveType() &&
- !property.getType().getSimpleName().equals("String") &&
- !property.getType().getSimpleName().equals("ByteSequence") )
- {
- String includeName = toCppType(property.getType());
- if( property.getType().isArrayType() )
- {
- JClass arrayType = property.getType().getArrayComponentType();
- if( arrayType.isPrimitiveType() )
- continue ;
- }
- if( includeName.startsWith("array<") )
- includeName = includeName.substring(6, includeName.length()-1);
- else if( includeName.startsWith("p<") )
- includeName = includeName.substring(2, includeName.length()-1);
-
- if( includeName.equals("IDataStructure") ) {
-out.println("#include \"activemq/"+includeName+".hpp\"");
- } else {
-out.println("#include \"activemq/command/"+includeName+".hpp\"");
- }
- }
- }
-out.println("");
-out.println("#include \"activemq/protocol/IMarshaller.hpp\"");
-out.println("#include \"ppr/io/IOutputStream.hpp\"");
-out.println("#include \"ppr/io/IInputStream.hpp\"");
-out.println("#include \"ppr/io/IOException.hpp\"");
-out.println("#include \"ppr/util/ifr/array\"");
-out.println("#include \"ppr/util/ifr/p\"");
-out.println("");
-out.println("namespace apache");
-out.println("{");
-out.println(" namespace activemq");
-out.println(" {");
-out.println(" namespace command");
-out.println(" {");
-out.println(" using namespace ifr;");
-out.println(" using namespace std;");
-out.println(" using namespace apache::activemq;");
-out.println(" using namespace apache::activemq::protocol;");
-out.println(" using namespace apache::ppr::io;");
-out.println("");
-out.println("/*");
-out.println(" *");
-out.println(" * Command and marshalling code for OpenWire format for "+className+"");
-out.println(" *");
-out.println(" *");
-out.println(" * NOTE!: This file is autogenerated - do not modify!");
-out.println(" * if you need to make a change, please see the Groovy scripts in the");
-out.println(" * activemq-core module");
-out.println(" *");
-out.println(" */");
-out.println("class "+className+" : public "+baseClass+"");
-out.println("{");
-out.println("protected:");
-
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- String type = toCppType(property.getType());
- String name = decapitalize(property.getSimpleName());
-out.println(" "+type+" "+name+" ;");
- }
-out.println("");
-out.println("public:");
-out.println(" const static unsigned char TYPE = "+getOpenWireOpCode(jclass)+";");
-out.println("");
-out.println("public:");
-out.println(" "+className+"() ;");
-out.println(" virtual ~"+className+"() ;");
-out.println("");
-out.println(" virtual unsigned char getDataStructureType() ;");
-
- for (Iterator iter = properties.iterator(); iter.hasNext();) {
- JProperty property = (JProperty) iter.next();
- String type = toCppType(property.getType());
- String propertyName = property.getSimpleName();
- String parameterName = decapitalize(propertyName);
-out.println("");
-out.println(" virtual "+type+" get"+propertyName+"() ;");
-out.println(" virtual void set"+propertyName+"("+type+" "+parameterName+") ;");
- }
-out.println("");
-out.println(" virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;");
-out.println(" virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;");
-out.println("} ;");
-out.println("");
-out.println("/* namespace */");
-out.println(" }");
-out.println(" }");
-out.println("}");
-out.println("");
-out.println("#endif /*ActiveMQ_"+className+"_hpp_*/");
-}
+
+ protected void generateFile(PrintWriter out) {
+ generateLicence(out);
+
+ out.println("#ifndef ActiveMQ_" + className + "_hpp_");
+ out.println("#define ActiveMQ_" + className + "_hpp_");
+ out.println("");
+ out.println("// Turn off warning message for ignored exception specification");
+ out.println("#ifdef _MSC_VER");
+ out.println("#pragma warning( disable : 4290 )");
+ out.println("#endif");
+ out.println("");
+ out.println("#include <string>");
+ out.println("#include \"activemq/command/" + baseClass + ".hpp\"");
+
+ List properties = getProperties();
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty)iter.next();
+ if (!property.getType().isPrimitiveType() && !property.getType().getSimpleName().equals("String") && !property.getType().getSimpleName().equals("ByteSequence")) {
+ String includeName = toCppType(property.getType());
+ if (property.getType().isArrayType()) {
+ JClass arrayType = property.getType().getArrayComponentType();
+ if (arrayType.isPrimitiveType()) {
+ continue;
+ }
+ }
+ if (includeName.startsWith("array<")) {
+ includeName = includeName.substring(6, includeName.length() - 1);
+ } else if (includeName.startsWith("p<")) {
+ includeName = includeName.substring(2, includeName.length() - 1);
+ }
+ if (includeName.equals("IDataStructure")) {
+ out.println("#include \"activemq/" + includeName + ".hpp\"");
+ } else {
+ out.println("#include \"activemq/command/" + includeName + ".hpp\"");
+ }
+ }
+ }
+ out.println("");
+ out.println("#include \"activemq/protocol/IMarshaller.hpp\"");
+ out.println("#include \"ppr/io/IOutputStream.hpp\"");
+ out.println("#include \"ppr/io/IInputStream.hpp\"");
+ out.println("#include \"ppr/io/IOException.hpp\"");
+ out.println("#include \"ppr/util/ifr/array\"");
+ out.println("#include \"ppr/util/ifr/p\"");
+ out.println("");
+ out.println("namespace apache");
+ out.println("{");
+ out.println(" namespace activemq");
+ out.println(" {");
+ out.println(" namespace command");
+ out.println(" {");
+ out.println(" using namespace ifr;");
+ out.println(" using namespace std;");
+ out.println(" using namespace apache::activemq;");
+ out.println(" using namespace apache::activemq::protocol;");
+ out.println(" using namespace apache::ppr::io;");
+ out.println("");
+ out.println("/*");
+ out.println(" *");
+ out.println(" * Command and marshalling code for OpenWire format for " + className + "");
+ out.println(" *");
+ out.println(" *");
+ out.println(" * NOTE!: This file is autogenerated - do not modify!");
+ out.println(" * if you need to make a change, please see the Groovy scripts in the");
+ out.println(" * activemq-core module");
+ out.println(" *");
+ out.println(" */");
+ out.println("class " + className + " : public " + baseClass + "");
+ out.println("{");
+ out.println("protected:");
+
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty)iter.next();
+ String type = toCppType(property.getType());
+ String name = decapitalize(property.getSimpleName());
+ out.println(" " + type + " " + name + " ;");
+ }
+ out.println("");
+ out.println("public:");
+ out.println(" const static unsigned char TYPE = " + getOpenWireOpCode(jclass) + ";");
+ out.println("");
+ out.println("public:");
+ out.println(" " + className + "() ;");
+ out.println(" virtual ~" + className + "() ;");
+ out.println("");
+ out.println(" virtual unsigned char getDataStructureType() ;");
+
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty)iter.next();
+ String type = toCppType(property.getType());
+ String propertyName = property.getSimpleName();
+ String parameterName = decapitalize(propertyName);
+ out.println("");
+ out.println(" virtual " + type + " get" + propertyName + "() ;");
+ out.println(" virtual void set" + propertyName + "(" + type + " " + parameterName + ") ;");
+ }
+ out.println("");
+ out.println(" virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;");
+ out.println(" virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;");
+ out.println("} ;");
+ out.println("");
+ out.println("/* namespace */");
+ out.println(" }");
+ out.println(" }");
+ out.println("}");
+ out.println("");
+ out.println("#endif /*ActiveMQ_" + className + "_hpp_*/");
+ }
}
|