Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 49204 invoked from network); 19 Feb 2009 22:13:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Feb 2009 22:13:58 -0000 Received: (qmail 25287 invoked by uid 500); 19 Feb 2009 22:13:58 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 25258 invoked by uid 500); 19 Feb 2009 22:13:58 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 25245 invoked by uid 99); 19 Feb 2009 22:13:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Feb 2009 14:13:57 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Feb 2009 22:13:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2809B23889B2; Thu, 19 Feb 2009 22:13:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r746025 [2/2] - in /activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache: ./ activemq/ activemq/openwire/ activemq/openwire/tool/ Date: Thu, 19 Feb 2009 22:13:31 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090219221332.2809B23889B2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java?rev=746025&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java (added) +++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java Thu Feb 19 22:13:30 2009 @@ -0,0 +1,719 @@ +/** + * + * 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. + * The ASF licenses this file to You 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.JAnnotation; +import org.codehaus.jam.JAnnotationValue; +import org.codehaus.jam.JClass; +import org.codehaus.jam.JProperty; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +/** + * + * @version $Revision: 381410 $ + */ +public class AmqCppMarshallingClassesGenerator extends AmqCppMarshallingHeadersGenerator { + + protected String getFilePostFix() { + return ".cpp"; + } + + protected String getProperClassName( String className ) { + + return className; + } + + /** + * Checks if the tightMarshal1 method needs an casted version of its + * dataStructure argument and then returns true or false to indicate this + * to the caller. + * @returns true if the tightMarshal1 method needs an info pointer. + */ + protected boolean checkNeedsInfoPointerTM1() { + + if( isMarshallerAware() ){ + return true; + } + + List properties = getProperties(); + for (Iterator iter = properties.iterator(); iter.hasNext();) { + JProperty property = (JProperty) iter.next(); + JClass propertyType = property.getType(); + String type = propertyType.getSimpleName(); + + if( !( type.equals("byte") ) && + !( type.equals("char") ) && + !( type.equals("short") ) && + !( type.equals("int") ) ) { + + return true; + } + + } + + return false; + } + + /** + * Checks if the tightMarshal2 method needs an casted version of its + * dataStructure argument and then returns true or false to indicate this + * to the caller. + * @returns true if the tightMarshal2 method needs an info pointer. + */ + protected boolean checkNeedsInfoPointerTM2() { + + if( isMarshallerAware() ){ + return true; + } + + List properties = getProperties(); + for (Iterator iter = properties.iterator(); iter.hasNext();) { + JProperty property = (JProperty) iter.next(); + JClass propertyType = property.getType(); + String type = propertyType.getSimpleName(); + + if( !type.equals("boolean") ) { + + return true; + } + + } + + return false; + } + + ////////////////////////////////////////////////////////////////////////////////////// + // This section is for the tight wire format encoding generator + ////////////////////////////////////////////////////////////////////////////////////// + + protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) { + + String setter = property.getSetter().getSimpleName(); + String type = property.getType().getSimpleName(); + String nativeType = toCppType(property.getType()); + String propertyName = property.getType().getSimpleName(); + + if( type.equals("boolean") ) { + out.println(" info->" + setter + "( bs->readBoolean() );"); + } + else if( type.equals("byte") ) { + out.println(" info->" + setter + "( dataIn->readByte() );"); + } + else if( type.equals("char") ) { + out.println(" info->" + setter + "( dataIn->readChar() );"); + } + else if( type.equals("short") ) { + out.println(" info->" + setter + "( dataIn->readShort() );"); + } + else if( type.equals("int") ) { + out.println(" info->" + setter + "( dataIn->readInt() );"); + } + else if( type.equals("long") ) { + out.println(" info->" + setter + "( tightUnmarshalLong( wireFormat, dataIn, bs ) );"); + } + else if( type.equals("String") ) { + out.println(" info->" + setter + "( tightUnmarshalString( dataIn, bs ) );"); + } + else if( type.equals("byte[]") || type.equals("ByteSequence") ) { + if( size != null ) { + out.println(" info->" + setter + "( tightUnmarshalConstByteArray( dataIn, bs, "+ size.asInt() +" ) );"); + } + else { + out.println(" info->" + setter + "( tightUnmarshalByteArray( dataIn, bs ) );"); + } + } + else if( isThrowable( property.getType() ) ) { + out.println(" info->" + setter + "( Pointer<"+nativeType+">( dynamic_cast< " + nativeType + "* >("); + out.println(" tightUnmarshalBrokerError( wireFormat, dataIn, bs ) ) ) );"); + } + else if( isCachedProperty(property) ) { + out.println(" info->" + setter + "( Pointer<"+nativeType+">( dynamic_cast< " + nativeType + "* >("); + out.println(" tightUnmarshalCachedObject( wireFormat, dataIn, bs ) ) ) );"); + } + else { + out.println(" info->" + setter + "( Pointer<"+nativeType+">( dynamic_cast< " + nativeType + "* >("); + out.println(" tightUnmarshalNestedObject( wireFormat, dataIn, bs ) ) ) );"); + } + } + + protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) { + JClass propertyType = property.getType(); + String arrayType = propertyType.getArrayComponentType().getSimpleName(); + String setter = property.getSetter().getSimpleName(); + String getter = property.getGetter().getSimpleName(); + out.println(); + if (size != null) { + out.println(" {"); + out.println(" " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];"); + out.println(" " + "for( int i = 0; i < " + size.asInt() + "; i++ ) {"); + out.println(" value[i] = (" + arrayType + ") tightUnmarshalNestedObject( wireFormat, dataIn, bs );"); + out.println(" }"); + out.println(" info->" + setter + "( value );"); + out.println(" }"); + } + else { + out.println(" if( bs->readBoolean() ) {"); + out.println(" short size = dataIn->readShort();"); + out.println(" info->" + getter + "().reserve( size );"); + out.println(" for( int i = 0; i < size; i++ ) {"); + out.println(" info->" + getter + "().push_back( Pointer<"+arrayType+">( dynamic_cast< " + arrayType + "* >("); + out.println(" tightUnmarshalNestedObject( wireFormat, dataIn, bs ) ) ) );"); + out.println(" }"); + out.println(" }"); + out.println(" else {"); + out.println(" info->" + getter + "().clear();"); + out.println(" }"); + } + } + + protected int generateTightMarshal1Body(PrintWriter out) { + List properties = getProperties(); + int baseSize = 0; + for (Iterator iter = properties.iterator(); iter.hasNext();) { + JProperty property = (JProperty) iter.next(); + JAnnotation annotation = property.getAnnotation("openwire:property"); + JAnnotationValue size = annotation.getValue("size"); + JClass propertyType = property.getType(); + String type = propertyType.getSimpleName(); + String getter = "info->" + property.getGetter().getSimpleName() + "()"; + + if (type.equals("boolean")) { + out.println(" bs->writeBoolean( " + getter + " );"); + } + else if (type.equals("byte")) { + baseSize += 1; + } + else if (type.equals("char")) { + baseSize += 2; + } + else if (type.equals("short")) { + baseSize += 2; + } + else if (type.equals("int")) { + baseSize += 4; + } + else if (type.equals("long")) { + out.println(" rc += tightMarshalLong1( wireFormat, " + getter + ", bs );"); + } + else if (type.equals("String")) { + out.print(""); + out.println(" rc += tightMarshalString1( " + getter + ", bs );" ); + } + else if (type.equals("byte[]") || type.equals("ByteSequence")) { + if (size == null) { + out.println(" bs->writeBoolean( " + getter + ".size() != 0 );" ); + out.println(" rc += " + getter + ".size() == 0 ? 0 : (int)" + getter + ".size() + 4;"); + } + else { + baseSize += size.asInt(); + } + } + else if (propertyType.isArrayType()) { + if (size != null) { + out.println(" rc += tightMarshalObjectArrayConstSize1( wireFormat, " + getter + ", bs, " + size.asInt() + " );"); + } + else { + out.println(" rc += tightMarshalObjectArray1( wireFormat, " + getter + ", bs );"); + } + } + else if (isThrowable(propertyType)) { + out.println(" rc += tightMarshalBrokerError1( wireFormat, " + getter + ".get(), bs );"); + } + else { + if (isCachedProperty(property)) { + out.println(" rc += tightMarshalCachedObject1( wireFormat, " + getter + ".get(), bs );"); + } + else { + out.println(" rc += tightMarshalNestedObject1( wireFormat, " + getter + ".get(), bs );"); + } + } + } + return baseSize; + } + + protected void generateTightMarshal2Body(PrintWriter out) { + List properties = getProperties(); + int count = 0; + for (Iterator iter = properties.iterator(); iter.hasNext();) { + JProperty property = (JProperty) iter.next(); + JAnnotation annotation = property.getAnnotation("openwire:property"); + JAnnotationValue size = annotation.getValue("size"); + JClass propertyType = property.getType(); + String type = propertyType.getSimpleName(); + String getter = "info->" + property.getGetter().getSimpleName() + "()"; + count++; + + if (type.equals("boolean")) { + out.println(" bs->readBoolean();"); + } + else if (type.equals("byte")) { + out.println(" dataOut->write( " + getter + " );"); + } + else if (type.equals("char")) { + out.println(" dataOut->write( " + getter + " );"); + } + else if (type.equals("short")) { + out.println(" dataOut->writeShort( " + getter + " );"); + } + else if (type.equals("int")) { + out.println(" dataOut->writeInt( " + getter + " );"); + } + else if (type.equals("long")) { + out.println(" tightMarshalLong2( wireFormat, " + getter + ", dataOut, bs );"); + } + else if (type.equals("String")) { + out.println(" tightMarshalString2( " + getter + ", dataOut, bs );"); + } + else if (type.equals("byte[]") || type.equals("ByteSequence")) { + if (size != null) { + out.println(" dataOut->write( (const unsigned char*)(&" + getter + "[0]), 0, " + size.asInt() + " );"); + } + else { + out.println(" if( bs->readBoolean() ) {"); + out.println(" dataOut->writeInt( (int)" + getter + ".size() );"); + out.println(" dataOut->write( (const unsigned char*)(&" + getter + "[0]), 0, (int)" + getter + ".size() );"); + out.println(" }"); + } + } + else if (propertyType.isArrayType()) { + if (size != null) { + out.println(" tightMarshalObjectArrayConstSize2( wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + " );"); + } + else { + out.println(" tightMarshalObjectArray2( wireFormat, " + getter + ", dataOut, bs );"); + } + } + else if( isThrowable(propertyType) ) { + out.println(" tightMarshalBrokerError2( wireFormat, " + getter + ".get(), dataOut, bs );"); + } + else { + if( isCachedProperty(property) ) { + out.println(" tightMarshalCachedObject2( wireFormat, "+getter+".get(), dataOut, bs );"); + } + else { + out.println(" tightMarshalNestedObject2( wireFormat, "+getter+".get(), dataOut, bs );"); + } + } + } + } + + ////////////////////////////////////////////////////////////////////////////////////// + // This section is for the loose wire format encoding generator + ////////////////////////////////////////////////////////////////////////////////////// + + protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) { + + String propertyName = property.getSimpleName(); + String type = property.getType().getSimpleName(); + String nativeType = toCppType(property.getType()); + String setter = property.getSetter().getSimpleName(); + + if (type.equals("boolean")) { + out.println(" info->" + setter + "( dataIn->readBoolean() );"); + } + else if (type.equals("byte")) { + out.println(" info->" + setter + "( dataIn->readByte() );"); + } + else if (type.equals("char")) { + out.println(" info->" + setter + "( dataIn->readChar() );"); + } + else if (type.equals("short")) { + out.println(" info->" + setter + "( dataIn->readShort() );"); + } + else if (type.equals("int")) { + out.println(" info->" + setter + "( dataIn->readInt() );"); + } + else if (type.equals("long")) { + out.println(" info->" + setter + "( looseUnmarshalLong( wireFormat, dataIn ) );"); + } + else if (type.equals("String")) { + out.println(" info->" + setter + "( looseUnmarshalString( dataIn ) );"); + } + else if (type.equals("byte[]") || type.equals("ByteSequence")) { + if (size != null) { + out.println(" info->" + setter + "( looseUnmarshalConstByteArray( dataIn, " + size.asInt() + " ) );"); + } + else { + out.println(" info->" + setter + "( looseUnmarshalByteArray( dataIn ) );"); + } + } + else if (isThrowable(property.getType())) { + out.println(" info->" + setter + "( Pointer<"+nativeType+">( dynamic_cast< " + nativeType + "* >("); + out.println(" looseUnmarshalBrokerError( wireFormat, dataIn ) ) ) );"); + } + else if (isCachedProperty(property)) { + out.println(" info->" + setter + "( Pointer<"+nativeType+">( dynamic_cast< " + nativeType + "* >( "); + out.println(" looseUnmarshalCachedObject( wireFormat, dataIn ) ) ) );"); + } + else { + out.println(" info->" + setter + "( Pointer<"+nativeType+">( dynamic_cast< " + nativeType + "* >( "); + out.println(" looseUnmarshalNestedObject( wireFormat, dataIn ) ) ) );"); + } + } + + protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) { + JClass propertyType = property.getType(); + String arrayType = propertyType.getArrayComponentType().getSimpleName(); + String propertyName = property.getSimpleName(); + String setter = property.getSetter().getSimpleName(); + String getter = property.getGetter().getSimpleName(); + + out.println(); + if (size != null) { + out.println(" {"); + out.println(" " + arrayType + "[] value = new " + arrayType + "[" + size.asInt() + "];"); + out.println(" " + "for( int i=0; i < " + size.asInt() + "; i++ ) {"); + out.println(" value[i] = (" + arrayType + ") looseUnmarshalNestedObject( wireFormat, dataIn );"); + out.println(" }"); + out.println(" info->" + setter + "( value );"); + out.println(" }"); + } + else { + out.println(" if( dataIn->readBoolean() ) {"); + out.println(" short size = dataIn->readShort();"); + out.println(" info->" + getter + "().reserve( size );"); + out.println(" for( int i = 0; i < size; i++ ) {"); + out.println(" info->" + getter + "().push_back( Pointer<"+arrayType+">( dynamic_cast<" + arrayType + "* >("); + out.println(" looseUnmarshalNestedObject( wireFormat, dataIn ) ) ) );"); + out.println(" }"); + out.println(" }"); + out.println(" else {"); + out.println(" info->" + getter + "().clear();"); + out.println(" }"); + } + } + + + protected void generateLooseMarshalBody(PrintWriter out) { + List properties = getProperties(); + for (Iterator iter = properties.iterator(); iter.hasNext();) { + JProperty property = (JProperty) iter.next(); + JAnnotation annotation = property.getAnnotation("openwire:property"); + JAnnotationValue size = annotation.getValue("size"); + JClass propertyType = property.getType(); + String type = propertyType.getSimpleName(); + String getter = "info->" + property.getGetter().getSimpleName() + "()"; + + if( type.equals( "boolean" ) ) { + out.println(" dataOut->writeBoolean( " + getter + " );"); + } + else if( type.equals("byte") ) { + out.println(" dataOut->write( " + getter + " );"); + } + else if( type.equals("char") ) { + out.println(" dataOut->write( " + getter + " );"); + } + else if( type.equals("short") ) { + out.println(" dataOut->writeShort( " + getter + " );"); + } + else if( type.equals("int")) { + out.println(" dataOut->writeInt( " + getter + " );"); + } + else if( type.equals("long") ) { + out.println(" looseMarshalLong( wireFormat, " + getter + ", dataOut );"); + } + else if( type.equals("String") ) { + out.println(" looseMarshalString( " + getter + ", dataOut );"); + } + else if( type.equals("byte[]") || type.equals("ByteSequence") ) { + if(size != null) { + out.println(" dataOut->write( (const unsigned char*)(&" + getter + "[0]), 0, (int)" + size.asInt() + " );"); + } + else { + out.println(" dataOut->write( " + getter + ".size() != 0 );"); + out.println(" if( " + getter + ".size() != 0 ) {"); + out.println(" dataOut->writeInt( (int)" + getter + ".size() );"); + out.println(" dataOut->write( (const unsigned char*)(&" + getter + "[0]), 0, (int)" + getter + ".size() );"); + out.println(" }"); + } + } + else if( propertyType.isArrayType() ) { + if (size != null) { + out.println(" looseMarshalObjectArrayConstSize( wireFormat, " + getter + ", dataOut, " + size.asInt() + " );"); + } + else { + out.println(" looseMarshalObjectArray( wireFormat, " + getter + ", dataOut );"); + } + } + else if( isThrowable( propertyType ) ) { + out.println(" looseMarshalBrokerError( wireFormat, " + getter + ".get(), dataOut );"); + } + else { + if( isCachedProperty( property ) ) { + out.println(" looseMarshalCachedObject( wireFormat, "+getter+".get(), dataOut );"); + } + else { + out.println(" looseMarshalNestedObject( wireFormat, "+getter+".get(), dataOut );"); + } + } + } + } + + + protected void generateFile(PrintWriter out) throws Exception { + generateLicence(out); + +out.println(""); +out.println("#include "); +out.println(""); +out.println("#include "); +out.println("#include "); +out.println("#include "); +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 Java Classes in the"); +out.println("// activemq-core module"); +out.println("//"); +out.println(""); +out.println("using namespace std;"); +out.println("using namespace activemq;"); +out.println("using namespace activemq::exceptions;"); +out.println("using namespace activemq::commands;"); +out.println("using namespace activemq::wireformat;"); +out.println("using namespace activemq::wireformat::openwire;"); +out.println("using namespace activemq::wireformat::openwire::marshal;"); +out.println("using namespace activemq::wireformat::openwire::utils;"); +out.println("using namespace activemq::wireformat::openwire::marshal::v"+getOpenwireVersion()+";"); +out.println("using namespace decaf;"); +out.println("using namespace decaf::io;"); +out.println("using namespace decaf::lang;"); +out.println(""); + + String typeName = jclass.getSimpleName().toUpperCase(); + + if( !isAbstractClass() ) { +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("DataStructure* "+className+"::createObject() const {"); +out.println(" return new "+jclass.getSimpleName()+"();"); +out.println("}"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("unsigned char "+className+"::getDataStructureType() const {"); +out.println(" return "+jclass.getSimpleName()+"::ID_"+typeName+";"); +out.println("}"); +out.println(""); + } + +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void "+className+"::tightUnmarshal( OpenWireFormat* wireFormat, DataStructure* dataStructure, DataInputStream* dataIn, BooleanStream* bs ) throw( decaf::io::IOException ) {"); +out.println(""); +out.println(" try {"); +out.println(""); +out.println(" "+baseClass+"::tightUnmarshal( wireFormat, dataStructure, dataIn, bs );"); +out.println(""); + + List properties = getProperties(); + boolean marshallerAware = isMarshallerAware(); + if( !properties.isEmpty() || marshallerAware ) { + + String properClassName = getProperClassName( jclass.getSimpleName() ); +out.println(" "+properClassName+"* info ="); +out.println(" dynamic_cast<"+properClassName+"*>( dataStructure );"); + } + + if( marshallerAware ) { +out.println(" info->beforeUnmarshal( wireFormat );"); +out.println(""); + } + + generateTightUnmarshalBody(out); + + if( marshallerAware ) { +out.println(""); +out.println(" info->afterUnmarshal( wireFormat );"); + } + +out.println(" }"); +out.println(" AMQ_CATCH_RETHROW( decaf::io::IOException )" ); +out.println(" AMQ_CATCH_EXCEPTION_CONVERT( exceptions::ActiveMQException, decaf::io::IOException )" ); +out.println(" AMQ_CATCHALL_THROW( decaf::io::IOException )" ); +out.println("}"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("int "+className+"::tightMarshal1( OpenWireFormat* wireFormat, DataStructure* dataStructure, BooleanStream* bs ) throw( decaf::io::IOException ) {"); +out.println(""); +out.println(" try {"); +out.println(""); + + if( checkNeedsInfoPointerTM1() ) { + String properClassName = getProperClassName( jclass.getSimpleName() ); +out.println(" "+properClassName+"* info ="); +out.println(" dynamic_cast<"+properClassName+"*>( dataStructure );"); +out.println(""); + } + + if( marshallerAware ) { +out.println(" info->beforeMarshal( wireFormat );"); + } + +out.println(" int rc = "+baseClass+"::tightMarshal1( wireFormat, dataStructure, bs );"); + + int baseSize = generateTightMarshal1Body(out); + +out.println(""); +out.println(" return rc + "+baseSize+";"); +out.println(" }"); +out.println(" AMQ_CATCH_RETHROW( decaf::io::IOException )" ); +out.println(" AMQ_CATCH_EXCEPTION_CONVERT( exceptions::ActiveMQException, decaf::io::IOException )" ); +out.println(" AMQ_CATCHALL_THROW( decaf::io::IOException )" ); +out.println("}"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void "+className+"::tightMarshal2( OpenWireFormat* wireFormat, DataStructure* dataStructure, DataOutputStream* dataOut, BooleanStream* bs ) throw( decaf::io::IOException ) {"); +out.println(""); +out.println(" try {"); +out.println(""); +out.println(" "+baseClass+"::tightMarshal2( wireFormat, dataStructure, dataOut, bs );"); +out.println(""); + + if( checkNeedsInfoPointerTM2() ) { + String properClassName = getProperClassName( jclass.getSimpleName() ); +out.println(" "+properClassName+"* info ="); +out.println(" dynamic_cast<"+properClassName+"*>( dataStructure );"); + } + + generateTightMarshal2Body(out); + + if( marshallerAware ) { +out.println(" info->afterMarshal( wireFormat );"); + } + +out.println(" }"); +out.println(" AMQ_CATCH_RETHROW( decaf::io::IOException )" ); +out.println(" AMQ_CATCH_EXCEPTION_CONVERT( exceptions::ActiveMQException, decaf::io::IOException )" ); +out.println(" AMQ_CATCHALL_THROW( decaf::io::IOException )" ); +out.println("}"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void "+className+"::looseUnmarshal( OpenWireFormat* wireFormat, DataStructure* dataStructure, DataInputStream* dataIn ) throw( decaf::io::IOException ) {"); +out.println(""); +out.println(" try {"); +out.println(""); +out.println(" "+baseClass+"::looseUnmarshal( wireFormat, dataStructure, dataIn );"); + + if( !properties.isEmpty() || marshallerAware ) { + String properClassName = getProperClassName( jclass.getSimpleName() ); +out.println(" "+properClassName+"* info ="); +out.println(" dynamic_cast<"+properClassName+"*>( dataStructure );"); + } + + if( marshallerAware ) { +out.println(" info->beforeUnmarshal( wireFormat );"); + } + + generateLooseUnmarshalBody(out); + + if( marshallerAware ) { +out.println(" info->afterUnmarshal( wireFormat );"); + } + +out.println(" }"); +out.println(" AMQ_CATCH_RETHROW( decaf::io::IOException )" ); +out.println(" AMQ_CATCH_EXCEPTION_CONVERT( exceptions::ActiveMQException, decaf::io::IOException )" ); +out.println(" AMQ_CATCHALL_THROW( decaf::io::IOException )" ); +out.println("}"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void "+className+"::looseMarshal( OpenWireFormat* wireFormat, DataStructure* dataStructure, DataOutputStream* dataOut ) throw( decaf::io::IOException ) {"); +out.println(""); +out.println(" try {"); +out.println(""); + + if( !properties.isEmpty() || marshallerAware ) { + String properClassName = getProperClassName( jclass.getSimpleName() ); +out.println(" "+properClassName+"* info ="); +out.println(" dynamic_cast<"+properClassName+"*>( dataStructure );"); + } + + if( marshallerAware ) { +out.println(" info->beforeMarshal( wireFormat );"); + } + +out.println(" "+baseClass+"::looseMarshal( wireFormat, dataStructure, dataOut );"); +out.println(""); + + generateLooseMarshalBody(out); + + if( marshallerAware ) { +out.println(" info->afterMarshal( wireFormat );"); + } + +out.println(" }"); +out.println(" AMQ_CATCH_RETHROW( decaf::io::IOException )" ); +out.println(" AMQ_CATCH_EXCEPTION_CONVERT( exceptions::ActiveMQException, decaf::io::IOException )" ); +out.println(" AMQ_CATCHALL_THROW( decaf::io::IOException )" ); +out.println("}"); +out.println(""); +} + + public void generateFactory(PrintWriter out) { + generateLicence(out); + +out.println("#include "); + + List list = new ArrayList(getConcreteClasses()); + Collections.sort(list, new Comparator(){ + public int compare(Object o1, Object o2) { + JClass c1 = (JClass) o1; + JClass c2 = (JClass) o2; + return c1.getSimpleName().compareTo(c2.getSimpleName()); + }}); + + for (Iterator iter = list.iterator(); iter.hasNext();) { + JClass jclass = (JClass) iter.next(); +out.println("#include "); + } + +out.println(""); +out.println("/*"); +out.println(" *"); +out.println(" * Command and marshaling code for OpenWire format for MarshallerFactory"); +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 Java Classes"); +out.println(" * in the activemq-openwire-generator module"); +out.println(" *"); +out.println(" */"); +out.println(""); +out.println("using namespace activemq;"); +out.println("using namespace activemq::wireformat;"); +out.println("using namespace activemq::wireformat::openwire;"); +out.println("using namespace activemq::wireformat::openwire::marshal;"); +out.println("using namespace activemq::wireformat::openwire::marshal::v"+getOpenwireVersion()+";"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void MarshallerFactory::configure( OpenWireFormat* format ) {"); +out.println(""); + + for (Iterator iter = list.iterator(); iter.hasNext();) { + JClass jclass = (JClass) iter.next(); +out.println(" format->addMarshaller( new "+jclass.getSimpleName()+"Marshaller() );"); +} + +out.println("}"); +out.println(""); + } +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java?rev=746025&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java (added) +++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java Thu Feb 19 22:13:30 2009 @@ -0,0 +1,329 @@ +/** + * + * 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. + * The ASF licenses this file to You 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 java.io.File; +import java.io.PrintWriter; +import java.util.ArrayList; + +import org.codehaus.jam.JClass; + +/** + * + * @version $Revision: 381410 $ + */ +public class AmqCppMarshallingHeadersGenerator extends JavaMarshallingGenerator { + + protected String targetDir="./src/main"; + + public Object run() { + filePostFix = getFilePostFix(); + if (destDir == null) { + destDir = new File(targetDir+"/activemq/wireformat/openwire/marshal/v"+getOpenwireVersion()); + } + return super.run(); + } + + protected void processClass(JClass jclass) { + super.processClass( jclass ); + } + + protected String getBaseClassName(JClass jclass) { + String answer = jclass.getSimpleName(); + + if( answer.equals("ActiveMQTextMessage") ) { + answer = "MessageMarshaller"; + } else if( answer.equals("ActiveMQBytesMessage") ) { + answer = "MessageMarshaller"; + } else if( answer.equals("ActiveMQMapMessage") ) { + answer = "MessageMarshaller"; + } else if( answer.equals("ActiveMQObjectMessage") ) { + answer = "MessageMarshaller"; + } else if( answer.equals("ActiveMQStreamMessage") ) { + answer = "MessageMarshaller"; + } + + // We didn't map it, so let the base class handle it. + if( answer.equals( jclass.getSimpleName() ) ) { + answer = super.getBaseClassName(jclass); + } + + return answer; + } + + public boolean isMarshallAware(JClass j) { + + String answer = jclass.getSimpleName(); + + if( answer.equals("ActiveMQTextMessage") ) { + return true; + } else if( answer.equals("ActiveMQBytesMessage") ) { + return true; + } else if( answer.equals("ActiveMQMapMessage") ) { + return true; + } else if( answer.equals("ActiveMQObjectMessage") ) { + return true; + } else if( answer.equals("ActiveMQStreamMessage") ) { + return true; + } else if( answer.equals("ActiveMBlobMessage") ) { + return true; + } else { + return super.isMarshallAware(jclass); + } + } + + protected String getFilePostFix() { + return ".h"; + } + + public String toCppType(JClass type) { + String name = type.getSimpleName(); + if (name.equals("String")) { + return "std::string"; + } + else if( type.isArrayType() ) { + if( name.equals( "byte[]" ) ) + name = "unsigned char[]"; + + JClass arrayClass = type.getArrayComponentType(); + + if( arrayClass.isPrimitiveType() ) { + return "std::vector<" + name.substring(0, name.length()-2) + ">"; + } else { + return "std::vector<" + name.substring(0, name.length()-2) + "*>"; + } + } + else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) { + return "BrokerError"; + } + else if( name.equals("BaseDataStructure" ) ){ + return "DataStructure"; + } + else if( name.equals("ByteSequence") ) { + return "std::vector"; + } + else if( name.equals("boolean") ) { + return "bool"; + } + else if( name.equals("long") ) { + return "long long"; + } + else if( name.equals("byte") ) { + return "unsigned char"; + } + else if( !type.isPrimitiveType() ) { + return name; + } + else { + return name; + } + } + + 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(""); +out.println("#ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_"); +out.println("#define _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_"); +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(""); + + if( baseClass.equals("BaseDataStreamMarshaller") ) { + out.println("#include "); + } else { + out.println("#include "); + } + +out.println(""); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println(""); +out.println("namespace activemq{"); +out.println("namespace wireformat{"); +out.println("namespace openwire{"); +out.println("namespace marshal{"); +out.println("namespace v"+getOpenwireVersion()+"{"); +out.println(""); +out.println(" /**"); +out.println(" * Marshaling code for Open Wire Format for "+className); +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 Java Classes"); +out.println(" * in the activemq-openwire-generator module"); +out.println(" */"); +out.println(" class AMQCPP_API "+className+" : public "+baseClass+" {"); +out.println(" public:"); +out.println(""); +out.println(" "+className+"() {}"); +out.println(" virtual ~"+className+"() {}"); +out.println(""); + + if( !isAbstractClass() ) { + +out.println(" /**"); +out.println(" * Creates a new instance of this marshalable type."); +out.println(" * @return new DataStructure object pointer caller owns it."); +out.println(" */"); +out.println(" virtual commands::DataStructure* createObject() const;"); +out.println(""); +out.println(" /**"); +out.println(" * Get the Data Structure Type that identifies this Marshaler"); +out.println(" * @return byte holding the data structure type value"); +out.println(" */"); +out.println(" virtual unsigned char getDataStructureType() const;"); +out.println(""); + } +out.println(" /**"); +out.println(" * Un-marshal an object instance from the data input stream"); +out.println(" * @param wireFormat - describes the wire format of the broker"); +out.println(" * @param o - Object to be un-marshaled"); +out.println(" * @param dataIn - BinaryReader that provides that data"); +out.println(" * @param bs - BooleanStream"); +out.println(" */"); +out.println(" virtual void tightUnmarshal( OpenWireFormat* wireFormat,"); +out.println(" commands::DataStructure* dataStructure,"); +out.println(" decaf::io::DataInputStream* dataIn,"); +out.println(" utils::BooleanStream* bs ) throw( decaf::io::IOException );"); +out.println(""); +out.println(" /**"); +out.println(" * Write the booleans that this object uses to a BooleanStream"); +out.println(" * @param wireFormat - describes the wire format of the broker"); +out.println(" * @param o - Object to be marshaled"); +out.println(" * @param bs - BooleanStream"); +out.println(" * @returns int"); +out.println(" */"); +out.println(" virtual int tightMarshal1( OpenWireFormat* wireFormat,"); +out.println(" commands::DataStructure* dataStructure,"); +out.println(" utils::BooleanStream* bs ) throw( decaf::io::IOException );"); +out.println(""); +out.println(" /**"); +out.println(" * Write a object instance to data output stream"); +out.println(" * @param wireFormat - describes the wire format of the broker"); +out.println(" * @param o - Object to be marshaled"); +out.println(" * @param dataOut - BinaryReader that provides that data sink"); +out.println(" * @param bs - BooleanStream"); +out.println(" */"); +out.println(" virtual void tightMarshal2( OpenWireFormat* wireFormat,"); +out.println(" commands::DataStructure* dataStructure,"); +out.println(" decaf::io::DataOutputStream* dataOut,"); +out.println(" utils::BooleanStream* bs ) throw( decaf::io::IOException );"); +out.println(""); +out.println(" /**"); +out.println(" * Un-marshal an object instance from the data input stream"); +out.println(" * @param wireFormat - describes the wire format of the broker"); +out.println(" * @param o - Object to be marshaled"); +out.println(" * @param dataIn - BinaryReader that provides that data source"); +out.println(" */"); +out.println(" virtual void looseUnmarshal( OpenWireFormat* wireFormat,"); +out.println(" commands::DataStructure* dataStructure,"); +out.println(" decaf::io::DataInputStream* dataIn ) throw( decaf::io::IOException );"); +out.println(""); +out.println(" /**"); +out.println(" * Write a object instance to data output stream"); +out.println(" * @param wireFormat - describs the wire format of the broker"); +out.println(" * @param o - Object to be marshaled"); +out.println(" * @param dataOut - BinaryWriter that provides that data sink"); +out.println(" */"); +out.println(" virtual void looseMarshal( OpenWireFormat* wireFormat,"); +out.println(" commands::DataStructure* dataStructure,"); +out.println(" decaf::io::DataOutputStream* dataOut ) throw( decaf::io::IOException );"); +out.println(""); +out.println(" };"); +out.println(""); +out.println("}}}}}"); +out.println(""); +out.println("#endif /*_ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_*/"); +out.println(""); + } + + public void generateFactory(PrintWriter out) { + generateLicence(out); +out.println("#ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_MARSHALERFACTORY_H_"); +out.println("#define _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_MARSHALERFACTORY_H_"); +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 "); +out.println(""); +out.println("namespace activemq{"); +out.println("namespace wireformat{"); +out.println("namespace openwire{"); +out.println("namespace marshal{"); +out.println("namespace v"+getOpenwireVersion()+"{"); +out.println(""); +out.println(" /**"); +out.println(" * Used to create marshallers for a specific version of the wire"); +out.println(" * protocol."); +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 Groovy scripts"); +out.println(" * in the activemq-openwire-generator module"); +out.println(" */"); +out.println(" class MarshallerFactory {"); +out.println(" public:"); +out.println(""); +out.println(" virtual ~MarshallerFactory() {};"); +out.println(""); +out.println(" virtual void configure( OpenWireFormat* format );"); +out.println(""); +out.println(" };"); +out.println(""); +out.println("}}}}}"); +out.println(""); +out.println("#endif /*_ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_V"+getOpenwireVersion()+"_MARSHALLERFACTORY_H_*/"); + } + + public String getTargetDir() { + return targetDir; + } + + public void setTargetDir(String targetDir) { + this.targetDir = targetDir; + } +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java?rev=746025&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java (added) +++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java Thu Feb 19 22:13:30 2009 @@ -0,0 +1,185 @@ +/** + * + * 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. + * The ASF licenses this file to You 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.JAnnotation; +import org.codehaus.jam.JAnnotationValue; +import org.codehaus.jam.JClass; +import org.codehaus.jam.JProperty; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +/** + * + * @version $Revision: 381410 $ + */ +public class AmqCppTestMarshallingClassesGenerator extends AmqCppTestMarshallingHeadersGenerator { + + protected String getFilePostFix() { + return ".cpp"; + } + + protected void generateFile(PrintWriter out) throws Exception { + generateLicence(out); + +out.println(""); +out.println("#include "); +out.println(""); +out.println("#include "); +out.println("#include "); +out.println(""); +out.println("CPPUNIT_TEST_SUITE_REGISTRATION( activemq::wireformat::openwire::marshal::v"+getOpenwireVersion()+"::"+className+" );"); +out.println(""); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("#include "); +out.println("//"); +out.println("// NOTE!: This file is autogenerated - do not modify!"); +out.println("// if you need to make a change, please see the Java Classes in the"); +out.println("// activemq-core module"); +out.println("//"); +out.println(""); +out.println("using namespace std;"); +out.println("using namespace activemq;"); +out.println("using namespace activemq::util;"); +out.println("using namespace activemq::exceptions;"); +out.println("using namespace activemq::commands;"); +out.println("using namespace activemq::wireformat;"); +out.println("using namespace activemq::wireformat::openwire;"); +out.println("using namespace activemq::wireformat::openwire::marshal;"); +out.println("using namespace activemq::wireformat::openwire::utils;"); +out.println("using namespace activemq::wireformat::openwire::marshal::v"+getOpenwireVersion()+";"); +out.println("using namespace decaf::io;"); +out.println("using namespace decaf::lang;"); +out.println("using namespace decaf::util;"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void "+className+"::test() {"); +out.println(""); +out.println(" "+ super.getTargetClassName(jclass) + " myMarshaller;"); +out.println(" "+ jclass.getSimpleName() + " myCommand;"); +out.println(" "+ jclass.getSimpleName() + "* myCommand2;"); +out.println(""); +out.println(" CPPUNIT_ASSERT( myMarshaller.getDataStructureType() == myCommand.getDataStructureType() );"); +out.println(" myCommand2 = dynamic_cast<"+jclass.getSimpleName()+"*>( myMarshaller.createObject() );"); +out.println(" CPPUNIT_ASSERT( myCommand2 != NULL );"); +out.println(" delete myCommand2;"); +out.println("}"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void "+className+"::testLooseMarshal() {"); +out.println(""); +out.println(" "+ super.getTargetClassName(jclass) +" marshaller;"); +out.println(" Properties props;"); +out.println(" OpenWireFormat openWireFormat( props );"); +out.println(""); +out.println(" // Configure for this test."); +out.println(" openWireFormat.setVersion( "+getOpenwireVersion()+" );"); +out.println(" openWireFormat.setTightEncodingEnabled( false );"); +out.println(""); +out.println(" "+jclass.getSimpleName()+" outCommand;"); +out.println(" "+jclass.getSimpleName()+" inCommand;"); +out.println(""); +out.println(" try {"); +out.println(""); +out.println(" // Marshal the dataStructure to a byte array."); +out.println(" ByteArrayOutputStream baos;"); +out.println(" DataOutputStream dataOut( &baos );"); +out.println(" dataOut.writeByte( outCommand.getDataStructureType() );"); +out.println(" marshaller.looseMarshal( &openWireFormat, &outCommand, &dataOut );"); +out.println(""); +out.println(" // Now read it back in and make sure it's all right."); +out.println(" ByteArrayInputStream bais( baos.toByteArray(), baos.size() );"); +out.println(" DataInputStream dataIn( &bais );"); +out.println(" unsigned char dataType = dataIn.readByte();"); +out.println(" CPPUNIT_ASSERT( dataType == outCommand.getDataStructureType() );"); +out.println(" marshaller.looseUnmarshal( &openWireFormat, &inCommand, &dataIn );"); +out.println(""); +out.println(" CPPUNIT_ASSERT( inCommand.equals( &outCommand ) == true );"); +out.println(""); +out.println(" } catch( ActiveMQException& e ) {"); +out.println(" e.printStackTrace();"); +out.println(" CPPUNIT_ASSERT( false );"); +out.println(" } catch( ... ) {"); +out.println(" CPPUNIT_ASSERT( false );"); +out.println(" }"); +out.println("}"); +out.println(""); +out.println("///////////////////////////////////////////////////////////////////////////////"); +out.println("void "+className+"::testTightMarshal() {"); +out.println(""); +out.println(" "+ super.getTargetClassName(jclass) +" marshaller;"); +out.println(" Properties props;"); +out.println(" OpenWireFormat openWireFormat( props );"); +out.println(""); +out.println(" // Configure for this test."); +out.println(" openWireFormat.setVersion( "+getOpenwireVersion()+" );"); +out.println(" openWireFormat.setTightEncodingEnabled( true );"); +out.println(""); +out.println(" "+jclass.getSimpleName()+" outCommand;"); +out.println(" "+jclass.getSimpleName()+" inCommand;"); +out.println(""); +out.println(" try {"); +out.println(""); +out.println(" // Marshal the dataStructure to a byte array."); +out.println(" ByteArrayOutputStream baos;"); +out.println(" DataOutputStream dataOut( &baos );"); +out.println(" // Phase 1 - count the size"); +out.println(" int size = 1;"); +out.println(" BooleanStream bs;"); +out.println(" size += marshaller.tightMarshal1( &openWireFormat, &outCommand, &bs );"); +out.println(" size += bs.marshalledSize();"); +out.println(" // Phase 2 - marshal"); +out.println(" dataOut.writeByte( outCommand.getDataStructureType() );"); +out.println(" bs.marshal( &dataOut );"); +out.println(" marshaller.tightMarshal2( &openWireFormat, &outCommand, &dataOut, &bs );"); +out.println(""); +out.println(" // Now read it back in and make sure it's all right."); +out.println(" ByteArrayInputStream bais( baos.toByteArray(), baos.size() );"); +out.println(" DataInputStream dataIn( &bais );"); +out.println(""); +out.println(" unsigned char dataType = dataIn.readByte();"); +out.println(" CPPUNIT_ASSERT( dataType == outCommand.getDataStructureType() );"); +out.println(" bs.clear();"); +out.println(" bs.unmarshal( &dataIn );"); +out.println(" marshaller.tightUnmarshal( &openWireFormat, &inCommand, &dataIn, &bs );"); +out.println(""); +out.println(" CPPUNIT_ASSERT( inCommand.equals( &outCommand ) == true );"); +out.println(""); +out.println(" } catch( ActiveMQException& e ) {"); +out.println(" e.printStackTrace();"); +out.println(" CPPUNIT_ASSERT( false );"); +out.println(" } catch( ... ) {"); +out.println(" CPPUNIT_ASSERT( false );"); +out.println(" }"); +out.println("}"); +out.println(""); + } + +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java?rev=746025&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java (added) +++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java Thu Feb 19 22:13:30 2009 @@ -0,0 +1,190 @@ +/** + * + * 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. + * The ASF licenses this file to You 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 java.io.File; +import java.io.PrintWriter; +import java.util.ArrayList; + +import org.codehaus.jam.JClass; + +/** + * + * @version $Revision: 381410 $ + */ +public class AmqCppTestMarshallingHeadersGenerator extends JavaMarshallingGenerator { + + protected String targetDir="./src/main"; + + protected void processClass(JClass jclass) { + + if( isAbstractClass() ) { + return; + } + + super.processClass( jclass ); + } + + protected void processFactory() {} + + public Object run() { + + filePostFix = getFilePostFix(); + if (destDir == null) { + destDir = new File(targetDir+"/activemq/wireformat/openwire/marshal/v"+getOpenwireVersion()); + } + return super.run(); + } + + protected String getClassName(JClass jclass) { + return super.getClassName(jclass) + "Test"; + } + + protected String getTargetClassName(JClass jclass) { + return super.getClassName(jclass); + } + + protected String getFilePostFix() { + return ".h"; + } + + public String toCppType(JClass type) { + String name = type.getSimpleName(); + if (name.equals("String")) { + return "std::string"; + } + else if( type.isArrayType() ) { + if( name.equals( "byte[]" ) ) + name = "unsigned char[]"; + + JClass arrayClass = type.getArrayComponentType(); + + if( arrayClass.isPrimitiveType() ) { + return "std::vector<" + name.substring(0, name.length()-2) + ">"; + } else { + return "std::vector<" + name.substring(0, name.length()-2) + "*>"; + } + } + else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) { + return "BrokerError"; + } + else if( name.equals("BaseDataStructure" ) ){ + return "DataStructure"; + } + else if( name.equals("ByteSequence") ) { + return "std::vector"; + } + else if( name.equals("boolean") ) { + return "bool"; + } + else if( name.equals("long") ) { + return "long long"; + } + else if( name.equals("byte") ) { + return "unsigned char"; + } + else if( !type.isPrimitiveType() ) { + return name; + } + else { + return name; + } + } + + 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(""); +out.println("#ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_"); +out.println("#define _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_"); +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 "); +out.println("#include "); +out.println(""); +out.println("namespace activemq{"); +out.println("namespace wireformat{"); +out.println("namespace openwire{"); +out.println("namespace marshal{"); +out.println("namespace v"+getOpenwireVersion()+"{"); +out.println(""); +out.println(" /**"); +out.println(" * Marshalling Test code for Open Wire Format for "+className); +out.println(" *"); +out.println(" * NOTE!: This file is autogenerated - do not modify!"); +out.println(" * if you need to make a change, please see the Java Classes"); +out.println(" * in the activemq-openwire-generator module"); +out.println(" */"); +out.println(" class "+className+" : public CppUnit::TestFixture {" ); +out.println(""); +out.println(" CPPUNIT_TEST_SUITE( "+className+" );"); +out.println(" CPPUNIT_TEST( test );"); +out.println(" CPPUNIT_TEST( testLooseMarshal );"); +out.println(" CPPUNIT_TEST( testTightMarshal );"); +out.println(" CPPUNIT_TEST_SUITE_END();"); +out.println(""); +out.println(" public:"); +out.println(""); +out.println(" "+className+"() {}"); +out.println(" virtual ~"+className+"() {}"); +out.println(""); +out.println(" /**"); +out.println(" * Test the marshaller and its marshalled type."); +out.println(" */"); +out.println(" virtual void test();"); +out.println(" virtual void testLooseMarshal();"); +out.println(" virtual void testTightMarshal();"); +out.println(""); +out.println(" };"); +out.println(""); +out.println("}}}}}"); +out.println(""); +out.println("#endif /*_ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_*/"); + } + + public String getTargetDir() { + return targetDir; + } + + public void setTargetDir(String targetDir) { + this.targetDir = targetDir; + } +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native