You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/04/29 02:46:10 UTC
svn commit: r769604 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main:
./ activemq/commands/ activemq/library/ activemq/wireformat/stomp/
activemq/wireformat/stomp/marshal/
Author: tabish
Date: Wed Apr 29 00:46:10 2009
New Revision: 769604
URL: http://svn.apache.org/viewvc?rev=769604&view=rev
Log:
An initial complete implementation of the StompWireFormat code. UNTESTED.
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.h (with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BaseCommand.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/Command.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ConsumerInfo.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ProducerInfo.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/RemoveSubscriptionInfo.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Wed Apr 29 00:46:10 2009
@@ -307,6 +307,7 @@
activemq/wireformat/stomp/StompResponseBuilder.cpp \
activemq/wireformat/stomp/StompCommandConstants.cpp \
activemq/wireformat/stomp/marshal/Marshaler.cpp \
+ activemq/wireformat/stomp/marshal/MarshalerHelper.cpp \
activemq/wireformat/stomp/StompWireFormatFactory.cpp \
activemq/wireformat/stomp/StompWireFormat.cpp \
activemq/wireformat/WireFormatRegistry.cpp \
@@ -842,6 +843,7 @@
activemq/wireformat/stomp/StompResponseBuilder.h \
activemq/wireformat/stomp/StompWireFormatFactory.h \
activemq/wireformat/stomp/marshal/Marshaler.h \
+ activemq/wireformat/stomp/marshal/MarshalerHelper.h \
activemq/wireformat/stomp/StompWireFormat.h \
activemq/wireformat/WireFormatFactory.h \
activemq/wireformat/MarshalAware.h \
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.cpp?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.cpp Wed Apr 29 00:46:10 2009
@@ -18,6 +18,11 @@
#include <decaf/lang/exceptions/NullPointerException.h>
#include <activemq/util/URISupport.h>
+#include <activemq/commands/ActiveMQTopic.h>
+#include <activemq/commands/ActiveMQQueue.h>
+#include <activemq/commands/ActiveMQTempTopic.h>
+#include <activemq/commands/ActiveMQTempQueue.h>
+
using namespace std;
using namespace activemq;
using namespace activemq::util;
@@ -39,6 +44,10 @@
const std::string ActiveMQDestination::COMPOSITE_SEPARATOR = ",";
const std::string ActiveMQDestination::DestinationFilter::ANY_CHILD = ">";
const std::string ActiveMQDestination::DestinationFilter::ANY_DESCENDENT = "*";
+const std::string ActiveMQDestination::QUEUE_QUALIFIED_PREFIX = "queue://";
+const std::string ActiveMQDestination::TOPIC_QUALIFIED_PREFIX = "topic://";
+const std::string ActiveMQDestination::TEMP_QUEUE_QUALIFED_PREFIX = "temp-queue://";
+const std::string ActiveMQDestination::TEMP_TOPIC_QUALIFED_PREFIX = "temp-topic://";
////////////////////////////////////////////////////////////////////////////////
ActiveMQDestination::ActiveMQDestination() {
@@ -160,3 +169,42 @@
}
return answer;
}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<ActiveMQDestination> ActiveMQDestination::createDestination( int type, const std::string& name ) {
+
+ Pointer<ActiveMQDestination> result;
+
+ if( name.find( QUEUE_QUALIFIED_PREFIX ) == 0 ) {
+ result.reset( new ActiveMQQueue( name.substr( QUEUE_QUALIFIED_PREFIX.length() ) ) );
+ return result;
+ } else if( name.find( TOPIC_QUALIFIED_PREFIX ) == 0 ) {
+ result.reset( new ActiveMQTopic( name.substr( TOPIC_QUALIFIED_PREFIX.length() ) ) );
+ return result;
+ } else if( name.find( TEMP_QUEUE_QUALIFED_PREFIX ) == 0 ) {
+ result.reset( new ActiveMQTempQueue( name.substr( TEMP_QUEUE_QUALIFED_PREFIX.length() ) ) );
+ return result;
+ } else if( name.find( TEMP_TOPIC_QUALIFED_PREFIX ) == 0 ) {
+ result.reset( new ActiveMQTempTopic( name.substr( TEMP_TOPIC_QUALIFED_PREFIX.length() ) ) );
+ return result;
+ }
+
+ switch( type ) {
+ case ActiveMQDestination::ACTIVEMQ_QUEUE:
+ result.reset( new ActiveMQQueue( name ) );
+ return result;
+ case ActiveMQDestination::ACTIVEMQ_TOPIC:
+ result.reset( new ActiveMQTopic( name ) );
+ return result;
+ case ActiveMQDestination::ACTIVEMQ_TEMPORARY_QUEUE:
+ result.reset( new ActiveMQTempQueue( name ) );
+ return result;
+ case ActiveMQDestination::ACTIVEMQ_TEMPORARY_TOPIC:
+ result.reset( new ActiveMQTempTopic( name ) );
+ return result;
+ default:
+ throw IllegalArgumentException(
+ __FILE__, __LINE__,
+ "Invalid default destination type: %d", type );
+ }
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.h?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQDestination.h Wed Apr 29 00:46:10 2009
@@ -27,6 +27,7 @@
#include <activemq/commands/BaseDataStructure.h>
#include <activemq/util/ActiveMQProperties.h>
#include <cms/Destination.h>
+#include <decaf/lang/Pointer.h>
#include <vector>
#include <string>
@@ -35,8 +36,10 @@
namespace activemq{
namespace commands{
+ using decaf::lang::Pointer;
+
class AMQCPP_API ActiveMQDestination : public BaseDataStructure {
- protected:
+ public:
enum DESTINATION_TYPE_IDS {
ACTIVEMQ_TOPIC = 1,
@@ -45,6 +48,8 @@
ACTIVEMQ_TEMPORARY_QUEUE = 4
};
+ protected:
+
struct DestinationFilter{
static const std::string ANY_CHILD;
static const std::string ANY_DESCENDENT;
@@ -79,6 +84,11 @@
static const std::string TEMP_POSTFIX;
static const std::string COMPOSITE_SEPARATOR;
+ static const std::string QUEUE_QUALIFIED_PREFIX;
+ static const std::string TOPIC_QUALIFIED_PREFIX;
+ static const std::string TEMP_QUEUE_QUALIFED_PREFIX;
+ static const std::string TEMP_TOPIC_QUALIFED_PREFIX;
+
// Cached transient data
bool exclusive;
bool ordered;
@@ -250,6 +260,16 @@
*/
static std::string getClientId( const ActiveMQDestination* destination );
+ /**
+ * Creates a Destination given the String Name to use and a Type.
+ *
+ * @param type - The Type of Destination to Create
+ * @param name - The Name to use in the creation of the Destination
+ *
+ * @return Pointer to a new ActiveMQDestination instance.
+ */
+ static Pointer<ActiveMQDestination> createDestination( int type, const std::string& name );
+
public:
/**
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BaseCommand.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BaseCommand.h?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BaseCommand.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BaseCommand.h Wed Apr 29 00:46:10 2009
@@ -115,6 +115,9 @@
virtual bool isConnectionInfo() const {
return false;
}
+ virtual bool isConsumerInfo() const {
+ return false;
+ }
virtual bool isBrokerInfo() const {
return false;
}
@@ -136,12 +139,18 @@
virtual bool isProducerAck() const {
return false;
}
+ virtual bool isProducerInfo() const {
+ return false;
+ }
virtual bool isResponse() const {
return false;
}
virtual bool isRemoveInfo() const {
return false;
}
+ virtual bool isRemoveSubscriptionInfo() const {
+ return false;
+ }
virtual bool isShutdownInfo() const {
return false;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/Command.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/Command.h?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/Command.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/Command.h Wed Apr 29 00:46:10 2009
@@ -81,6 +81,7 @@
* and we save several casts and some ugly code by just adding these here.
*/
virtual bool isConnectionInfo() const = 0;
+ virtual bool isConsumerInfo() const = 0;
virtual bool isBrokerInfo() const = 0;
virtual bool isKeepAliveInfo() const = 0;
virtual bool isMessage() const = 0;
@@ -88,8 +89,10 @@
virtual bool isMessageDispatch() const = 0;
virtual bool isMessageDispatchNotification() const = 0;
virtual bool isProducerAck() const = 0;
+ virtual bool isProducerInfo() const = 0;
virtual bool isResponse() const = 0;
virtual bool isRemoveInfo() const = 0;
+ virtual bool isRemoveSubscriptionInfo() const = 0;
virtual bool isShutdownInfo() const = 0;
virtual bool isTransactionInfo() const = 0;
virtual bool isWireFormatInfo() const = 0;
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ConsumerInfo.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ConsumerInfo.h?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ConsumerInfo.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ConsumerInfo.h Wed Apr 29 00:46:10 2009
@@ -177,6 +177,13 @@
virtual void setNoRangeAcks( bool noRangeAcks );
/**
+ * @return an answer of true to the isConsumerInfo() query.
+ */
+ virtual bool isConsumerInfo() const {
+ return true;
+ }
+
+ /**
* Allows a Visitor to visit this command and return a response to the
* command based on the command type being visited. The command will call
* the proper processXXX method in the visitor.
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ProducerInfo.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ProducerInfo.h?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ProducerInfo.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ProducerInfo.h Wed Apr 29 00:46:10 2009
@@ -125,6 +125,13 @@
virtual void setWindowSize( int windowSize );
/**
+ * @return an answer of true to the isProducerInfo() query.
+ */
+ virtual bool isProducerInfo() const {
+ return true;
+ }
+
+ /**
* Allows a Visitor to visit this command and return a response to the
* command based on the command type being visited. The command will call
* the proper processXXX method in the visitor.
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/RemoveSubscriptionInfo.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/RemoveSubscriptionInfo.h?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/RemoveSubscriptionInfo.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/RemoveSubscriptionInfo.h Wed Apr 29 00:46:10 2009
@@ -115,6 +115,13 @@
virtual void setClientId( const std::string& clientId );
/**
+ * @return an answer of true to the isRemoveSubscriptionInfo() query.
+ */
+ virtual bool isRemoveSubscriptionInfo() const {
+ return true;
+ }
+
+ /**
* Allows a Visitor to visit this command and return a response to the
* command based on the command type being visited. The command will call
* the proper processXXX method in the visitor.
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp Wed Apr 29 00:46:10 2009
@@ -21,7 +21,7 @@
#include <activemq/wireformat/WireFormatRegistry.h>
#include <activemq/transport/TransportRegistry.h>
-//#include <activemq/wireformat/stomp/StompWireFormatFactory.h>
+#include <activemq/wireformat/stomp/StompWireFormatFactory.h>
#include <activemq/wireformat/openwire/OpenWireFormatFactory.h>
#include <activemq/transport/mock/MockTransportFactory.h>
@@ -67,8 +67,8 @@
WireFormatRegistry::getInstance().registerFactory(
"openwire", new wireformat::openwire::OpenWireFormatFactory() );
-// WireFormatRegistry::getInstance().registerFactory(
-// "stomp", new wireformat::stomp::StompWireFormatFactory() );
+ WireFormatRegistry::getInstance().registerFactory(
+ "stomp", new wireformat::stomp::StompWireFormatFactory() );
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp Wed Apr 29 00:46:10 2009
@@ -56,6 +56,12 @@
Pointer<StompFrame> frame = marshaler.marshal( command );
+ // Some commands just don't translate to Stomp Commands, we ignore them
+ // and hope that bad things don't happen.
+ if( frame == NULL ) {
+ return;
+ }
+
// Write the command.
const string& cmdString = frame->getCommand();
out->write( (unsigned char*)cmdString.c_str(), 0, cmdString.length() );
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp Wed Apr 29 00:46:10 2009
@@ -21,23 +21,38 @@
#include <activemq/wireformat/stomp/StompCommandConstants.h>
#include <activemq/wireformat/stomp/StompFrame.h>
+#include <activemq/core/ActiveMQConstants.h>
#include <activemq/commands/ActiveMQMessage.h>
#include <activemq/commands/ActiveMQTextMessage.h>
#include <activemq/commands/ActiveMQBytesMessage.h>
#include <activemq/commands/Response.h>
#include <activemq/commands/BrokerError.h>
+#include <activemq/commands/MessageAck.h>
+#include <activemq/commands/ConnectionInfo.h>
#include <activemq/commands/ExceptionResponse.h>
+#include <activemq/commands/ShutdownInfo.h>
+#include <activemq/commands/RemoveInfo.h>
+#include <activemq/commands/TransactionInfo.h>
+#include <activemq/commands/LocalTransactionId.h>
+#include <activemq/commands/ProducerInfo.h>
+#include <activemq/commands/ConsumerInfo.h>
+#include <activemq/commands/RemoveSubscriptionInfo.h>
+#include <decaf/lang/exceptions/ClassCastException.h>
+#include <decaf/lang/Boolean.h>
#include <decaf/lang/Integer.h>
#include <decaf/io/IOException.h>
using namespace activemq;
+using namespace activemq::core;
using namespace activemq::commands;
using namespace activemq::exceptions;
using namespace activemq::wireformat;
using namespace activemq::wireformat::stomp;
using namespace activemq::wireformat::stomp::marshal;
+using namespace decaf;
using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
using namespace decaf::io;
////////////////////////////////////////////////////////////////////////////////
@@ -61,7 +76,7 @@
// We didn't seem to know what it was we got, so throw an exception.
throw decaf::io::IOException(
__FILE__, __LINE__,
- "Marshaler::marshal - No Command Created from frame");
+ "Marshaler::marshal - No Command Created from frame" );
}
AMQ_CATCH_RETHROW( decaf::io::IOException )
AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, decaf::io::IOException )
@@ -87,6 +102,18 @@
return this->marshalConnectionInfo( command );
} else if( command->isTransactionInfo() ) {
return this->marshalTransactionInfo( command );
+ } else if( command->isConsumerInfo() ) {
+ return this->marshalConsumerInfo( command );
+ } else if( command->isRemoveSubscriptionInfo() ) {
+ return this->marshalRemoveSubscriptionInfo( command );
+ } else if( command->isResponseRequired() ) {
+
+ // Send a fake Unsub command and ask for a receipt.
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::UNSUBSCRIBE );
+ frame->setProperty( StompCommandConstants::HEADER_ID, "-1" );
+ frame->setProperty( StompCommandConstants::HEADER_RECEIPT_REQUIRED,
+ Integer::toString( command->getCommandId() ) );
}
// Ignoring this command.
@@ -101,13 +128,25 @@
////////////////////////////////////////////////////////////////////////////////
Pointer<Command> Marshaler::unmarshalMessage( const Pointer<StompFrame>& frame ) {
-// if( !frame->getProperties().hasProperty(
-// CommandConstants::toString(
-// CommandConstants::HEADER_CONTENTLENGTH ) ) ) {
-// command = new TextMessageCommand( frame );
-// } else {
-// command = new BytesMessageCommand( frame );
-// }
+ Pointer<Message> message;
+
+ // Convert from the Frame to standard message properties.
+ helper.convertProperties( frame, message );
+
+ // Check for Content length, that tells us if its a Text or Bytes Message
+ if( frame->removeProperty( StompCommandConstants::HEADER_CONTENTLENGTH ) != "" ) {
+ message.reset( new ActiveMQBytesMessage() );
+ message->setContent( frame->getBody() );
+ } else {
+ Pointer<ActiveMQTextMessage> txtMessage( new ActiveMQTextMessage() );
+
+ if( frame->getBodyLength() > 0 ) {
+ std::string text( (char*)( &(frame->getBody()[0]) ), frame->getBodyLength() );
+ txtMessage->setText( text );
+ }
+
+ message = txtMessage.dynamicCast<Message>();
+ }
return Pointer<Command>();
}
@@ -115,7 +154,16 @@
////////////////////////////////////////////////////////////////////////////////
Pointer<Command> Marshaler::unmarshalReceipt( const Pointer<StompFrame>& frame ){
- return Pointer<Command>();
+ Pointer<Response> response( new Response() );
+ if( frame->hasProperty( StompCommandConstants::HEADER_RECEIPTID ) ) {
+ response->setCorrelationId( Integer::parseInt(
+ frame->getProperty( StompCommandConstants::HEADER_RECEIPTID ) ) );
+ } else {
+ throw IOException(
+ __FILE__, __LINE__, "Error, Connected Command has no Response ID." );
+ }
+
+ return response;
}
////////////////////////////////////////////////////////////////////////////////
@@ -156,35 +204,168 @@
////////////////////////////////////////////////////////////////////////////////
Pointer<StompFrame> Marshaler::marshalMessage( const Pointer<Command>& command ) {
- return Pointer<StompFrame>();
+ Pointer<Message> message = command.dynamicCast<Message>();
+
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::SEND );
+
+ // Convert the standard headers to the Stomp Format.
+ helper.convertProperties( message, frame );
+
+ // Convert the Content
+ try{
+ Pointer<ActiveMQTextMessage> txtMessage = message.dynamicCast<ActiveMQTextMessage>();
+ std::string text = txtMessage->getText();
+ frame->setBody( (unsigned char*)text.c_str(), text.length() );
+ return frame;
+ } catch( ClassCastException& ex ) {}
+
+ try{
+ Pointer<ActiveMQBytesMessage> bytesMessage = message.dynamicCast<ActiveMQBytesMessage>();
+ frame->setBody( bytesMessage->getBodyBytes(), bytesMessage->getBodyLength() );
+ return frame;
+ } catch( ClassCastException& ex ) {}
+
+ throw UnsupportedOperationException(
+ __FILE__, __LINE__,
+ "Stomp Marshaler can't marshal message of type: %s",
+ typeid( message.get() ).name() );
}
////////////////////////////////////////////////////////////////////////////////
Pointer<StompFrame> Marshaler::marshalAck( const Pointer<Command>& command ) {
- return Pointer<StompFrame>();
+ Pointer<MessageAck> ack = command.dynamicCast<MessageAck>();
+
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::ACK );
+ frame->setProperty( StompCommandConstants::HEADER_MESSAGEID,
+ helper.convertMessageId( ack->getLastMessageId() ) );
+
+ if( ack->getTransactionId() != NULL ) {
+ frame->setProperty( StompCommandConstants::HEADER_TRANSACTIONID,
+ helper.convertTransactionId( ack->getTransactionId() ) );
+ }
+
+ return frame;
}
////////////////////////////////////////////////////////////////////////////////
Pointer<StompFrame> Marshaler::marshalConnectionInfo( const Pointer<Command>& command ) {
- return Pointer<StompFrame>();
+ Pointer<ConnectionInfo> info = command.dynamicCast<ConnectionInfo>();
+
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::CONNECT );
+ frame->setProperty( StompCommandConstants::HEADER_CLIENT_ID, info->getClientId() );
+ frame->setProperty( StompCommandConstants::HEADER_LOGIN, info->getUserName() );
+ frame->setProperty( StompCommandConstants::HEADER_PASSWORD, info->getPassword() );
+ frame->setProperty( StompCommandConstants::HEADER_REQUESTID,
+ Integer::toString( info->getCommandId() ) );
+
+ return frame;
}
////////////////////////////////////////////////////////////////////////////////
Pointer<StompFrame> Marshaler::marshalTransactionInfo( const Pointer<Command>& command ) {
- return Pointer<StompFrame>();
+ Pointer<TransactionInfo> info = command.dynamicCast<TransactionInfo>();
+ Pointer<LocalTransactionId> id = info->getTransactionId().dynamicCast<LocalTransactionId>();
+
+ Pointer<StompFrame> frame( new StompFrame() );
+
+ if( info->getType() == ActiveMQConstants::TRANSACTION_STATE_BEGIN ) {
+ frame->setCommand( StompCommandConstants::BEGIN );
+ } else if( info->getType() == ActiveMQConstants::TRANSACTION_STATE_ROLLBACK ) {
+ frame->setCommand( StompCommandConstants::ABORT );
+ } else if( info->getType() == ActiveMQConstants::TRANSACTION_STATE_COMMITONEPHASE ) {
+ frame->setCommand( StompCommandConstants::COMMIT );
+ }
+
+ frame->setProperty( StompCommandConstants::HEADER_TRANSACTIONID,
+ helper.convertTransactionId( info->getTransactionId() ) );
+
+ return frame;
}
////////////////////////////////////////////////////////////////////////////////
-Pointer<StompFrame> Marshaler::marshalShutdownInfo( const Pointer<Command>& command ) {
+Pointer<StompFrame> Marshaler::marshalShutdownInfo( const Pointer<Command>& command AMQCPP_UNUSED ) {
- return Pointer<StompFrame>();
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::CONNECT );
+ return frame;
}
////////////////////////////////////////////////////////////////////////////////
Pointer<StompFrame> Marshaler::marshalRemoveInfo( const Pointer<Command>& command ) {
+ Pointer<RemoveInfo> info = command.dynamicCast<RemoveInfo>();
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::UNSUBSCRIBE );
+
+ try{
+ Pointer<ConsumerId> id = info->getObjectId().dynamicCast<ConsumerId>();
+ frame->setProperty( StompCommandConstants::HEADER_ID, helper.convertConsumerId( id ) );
+ return frame;
+ } catch( ClassCastException& ex ) {}
+
return Pointer<StompFrame>();
}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<StompFrame> Marshaler::marshalConsumerInfo( const Pointer<Command>& command ) {
+
+ Pointer<ConsumerInfo> info = command.dynamicCast<ConsumerInfo>();
+
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::SUBSCRIBE );
+
+ frame->setProperty( StompCommandConstants::HEADER_DESTINATION,
+ helper.convertDestination( info->getDestination() ) );
+ frame->setProperty( StompCommandConstants::HEADER_ID,
+ helper.convertConsumerId( info->getConsumerId() ) );
+
+ frame->setProperty( StompCommandConstants::HEADER_SUBSCRIPTIONNAME,
+ info->getSubscriptionName() );
+ frame->setProperty( StompCommandConstants::HEADER_SELECTOR,
+ info->getSelector() );
+ frame->setProperty( StompCommandConstants::HEADER_ACK, "client" );
+
+ if( info->isNoLocal() ) {
+ frame->setProperty( StompCommandConstants::HEADER_NOLOCAL, "true" );
+ }
+
+ frame->setProperty( StompCommandConstants::HEADER_DISPATCH_ASYNC,
+ Boolean::toString( info->isDispatchAsync() ) );
+
+ if( info->isExclusive() ) {
+ frame->setProperty( StompCommandConstants::HEADER_EXCLUSIVE, "true" );
+ }
+
+ frame->setProperty( StompCommandConstants::HEADER_MAXPENDINGMSGLIMIT,
+ Integer::toString( info->getMaximumPendingMessageLimit() ) );
+ frame->setProperty( StompCommandConstants::HEADER_PREFETCHSIZE,
+ Integer::toString( info->getPrefetchSize() ) );
+ frame->setProperty( StompCommandConstants::HEADER_CONSUMERPRIORITY,
+ Integer::toString( info->getPriority() ) );
+
+ if( info->isRetroactive() ) {
+ frame->setProperty( StompCommandConstants::HEADER_RETROACTIVE, "true" );
+ }
+
+ return frame;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<StompFrame> Marshaler::marshalRemoveSubscriptionInfo( const Pointer<Command>& command ) {
+
+ Pointer<RemoveSubscriptionInfo> info = command.dynamicCast<RemoveSubscriptionInfo>();
+ Pointer<StompFrame> frame( new StompFrame() );
+ frame->setCommand( StompCommandConstants::UNSUBSCRIBE );
+
+ frame->setProperty( StompCommandConstants::HEADER_ID, info->getClientId() );
+ frame->setProperty( StompCommandConstants::HEADER_SUBSCRIPTIONNAME,
+ info->getSubcriptionName() );
+
+ return frame;
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.h?rev=769604&r1=769603&r2=769604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/Marshaler.h Wed Apr 29 00:46:10 2009
@@ -21,6 +21,7 @@
#include <activemq/util/Config.h>
#include <activemq/commands/Command.h>
#include <activemq/wireformat/stomp/StompFrame.h>
+#include <activemq/wireformat/stomp/marshal/MarshalerHelper.h>
#include <decaf/io/IOException.h>
#include <decaf/lang/Pointer.h>
@@ -36,6 +37,10 @@
* Interface for all marshalers between Commands and Stomp frames.
*/
class AMQCPP_API Marshaler {
+ private:
+
+ MarshalerHelper helper;
+
public:
Marshaler() {}
@@ -72,6 +77,8 @@
Pointer<StompFrame> marshalTransactionInfo( const Pointer<Command>& command );
Pointer<StompFrame> marshalShutdownInfo( const Pointer<Command>& command );
Pointer<StompFrame> marshalRemoveInfo( const Pointer<Command>& command );
+ Pointer<StompFrame> marshalConsumerInfo( const Pointer<Command>& command );
+ Pointer<StompFrame> marshalRemoveSubscriptionInfo( const Pointer<Command>& command );
};
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.cpp?rev=769604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.cpp Wed Apr 29 00:46:10 2009
@@ -0,0 +1,330 @@
+/*
+ * 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.
+ */
+
+#include "MarshalerHelper.h"
+
+#include <activemq/wireformat/stomp/StompCommandConstants.h>
+#include <activemq/commands/LocalTransactionId.h>
+
+#include <decaf/util/StringTokenizer.h>
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Boolean.h>
+#include <decaf/lang/Long.h>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::commands;
+using namespace activemq::wireformat;
+using namespace activemq::wireformat::stomp;
+using namespace activemq::wireformat::stomp::marshal;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void MarshalerHelper::convertProperties( const Pointer<StompFrame>& frame,
+ const Pointer<Message>& message ) {
+
+ const std::string destination =
+ frame->removeProperty( StompCommandConstants::HEADER_DESTINATION );
+
+ // Destination creation.
+ message->setDestination( convertDestination( destination ) );
+
+ // the standard JMS headers
+ message->setCorrelationId( StompCommandConstants::HEADER_CORRELATIONID );
+
+ if( frame->hasProperty( StompCommandConstants::HEADER_EXPIRES ) ) {
+ message->setExpiration( Integer::parseInt(
+ frame->removeProperty( StompCommandConstants::HEADER_EXPIRES ) ) );
+ }
+
+ if( frame->hasProperty( StompCommandConstants::HEADER_JMSPRIORITY ) ) {
+ message->setPriority( Integer::parseInt(
+ frame->removeProperty( StompCommandConstants::HEADER_JMSPRIORITY ) ) );
+ }
+
+ if( frame->hasProperty( StompCommandConstants::HEADER_TYPE ) ) {
+ message->setType( frame->removeProperty( StompCommandConstants::HEADER_TYPE ) );
+ }
+
+ if( frame->hasProperty( StompCommandConstants::HEADER_REPLYTO ) ) {
+ message->setReplyTo( convertDestination(
+ frame->removeProperty( StompCommandConstants::HEADER_REPLYTO ) ) );
+ }
+
+ if( frame->hasProperty( StompCommandConstants::HEADER_PERSISTENT ) ) {
+ message->setPersistent( Boolean::parseBoolean(
+ frame->removeProperty( StompCommandConstants::HEADER_PERSISTENT ) ) );
+ }
+
+ if( frame->hasProperty( StompCommandConstants::HEADER_TRANSACTIONID ) ) {
+ std::string transactionId =
+ frame->removeProperty( StompCommandConstants::HEADER_TRANSACTIONID );
+ message->setTransactionId( convertTransactionId( transactionId ) );
+ }
+
+ // Copy the general headers over to the Message.
+ std::vector< std::pair<std::string, std::string> > properties = frame->getProperties().toArray();
+ std::vector< std::pair<std::string, std::string> >::const_iterator iter = properties.begin();
+
+ for( ; iter != properties.end(); ++iter ) {
+ message->getMessageProperties().setString( iter->first, iter->second );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MarshalerHelper::convertProperties( const Pointer<Message>& message,
+ const Pointer<StompFrame>& frame ) {
+
+ frame->setProperty( StompCommandConstants::HEADER_DESTINATION,
+ convertDestination( message->getDestination() ) );
+ frame->setProperty( StompCommandConstants::HEADER_MESSAGEID,
+ convertMessageId( message->getMessageId() ) );
+
+ if( message->getCorrelationId() != "" ) {
+ frame->setProperty( StompCommandConstants::HEADER_CORRELATIONID,
+ message->getCorrelationId() );
+ }
+
+ frame->setProperty( StompCommandConstants::HEADER_EXPIRES,
+ Long::toString( message->getExpiration() ) );
+ frame->setProperty( StompCommandConstants::HEADER_PERSISTENT,
+ Boolean::toString( message->isPersistent() ) );
+
+ if( message->getRedeliveryCounter() != 0 ) {
+ frame->setProperty( StompCommandConstants::HEADER_REDELIVERED, "true" );
+ }
+
+ frame->setProperty( StompCommandConstants::HEADER_JMSPRIORITY,
+ Integer::toString( message->getPriority() ) );
+
+ if( message->getReplyTo() != NULL ) {
+ frame->setProperty( StompCommandConstants::HEADER_REPLYTO,
+ convertDestination( message->getReplyTo() ) );
+ }
+
+ frame->setProperty( StompCommandConstants::HEADER_TIMESTAMP,
+ Long::toString( message->getTimestamp() ) );
+
+ if( message->getType() != "" ) {
+ frame->setProperty( StompCommandConstants::HEADER_TYPE, message->getType() );
+ }
+
+ if( message->getTransactionId() != NULL ) {
+ frame->setProperty( StompCommandConstants::HEADER_TRANSACTIONID,
+ convertTransactionId( message->getTransactionId() ) );
+ }
+
+ std::vector<std::string> keys = message->getMessageProperties().keySet();
+ std::vector<std::string>::const_iterator iter = keys.begin();
+
+ for( ; iter != keys.end(); ++iter ) {
+
+ // TODO - This will fail if the type isn't string.
+ frame->setProperty( *iter, message->getMessageProperties().getString( *iter ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string MarshalerHelper::convertDestination( const Pointer<ActiveMQDestination>& destination ) {
+
+ if( destination == NULL ) {
+ return "";
+ } else {
+
+ switch( destination->getDestinationType() ) {
+
+ case ActiveMQDestination::ACTIVEMQ_TOPIC:
+ return std::string( "/topic/" ) + destination->getPhysicalName();
+ case ActiveMQDestination::ACTIVEMQ_TEMPORARY_TOPIC:
+
+ if( destination->getPhysicalName().find( "/remote-temp-topic/" ) == 0 ) {
+ return destination->getPhysicalName();
+ } else {
+ return std::string( "/temp-topic/" ) + destination->getPhysicalName();
+ }
+
+ case ActiveMQDestination::ACTIVEMQ_TEMPORARY_QUEUE:
+
+ if( destination->getPhysicalName().find( "/remote-temp-queue/" ) == 0 ) {
+ return destination->getPhysicalName();
+ } else {
+ return std::string( "/temp-queue/" ) + destination->getPhysicalName();
+ }
+
+ default:
+ return std::string( "/queue/" ) + destination->getPhysicalName();
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<ActiveMQDestination> MarshalerHelper::convertDestination( const std::string& destination ) {
+
+ if( destination == "" ) {
+ return Pointer<ActiveMQDestination>();
+ }
+
+ int type = 0;
+ std::string dest = "";
+
+ if( destination.find( "/queue/" ) == 0 ) {
+ dest = destination.substr( 7 );
+ type = ActiveMQDestination::ACTIVEMQ_QUEUE;
+ } else if( destination.find( "/topic/" ) == 0 ) {
+ dest = destination.substr( 7 );
+ type = ActiveMQDestination::ACTIVEMQ_TOPIC;
+ } else if( destination.find( "/temp-topic/" ) == 0 ) {
+ dest = destination.substr( 12 );
+ type = ActiveMQDestination::ACTIVEMQ_TEMPORARY_TOPIC;
+ } else if( destination.find( "/temp-queue/" ) == 0 ) {
+ dest = destination.substr( 12 );
+ type = ActiveMQDestination::ACTIVEMQ_TEMPORARY_QUEUE;
+ } else if( destination.find( "/remote-temp-topic/" ) == 0 ) {
+ type = ActiveMQDestination::ACTIVEMQ_TEMPORARY_TOPIC;
+ } else if( destination.find( "/remote-temp-queue/" ) == 0 ) {
+ type = ActiveMQDestination::ACTIVEMQ_TEMPORARY_QUEUE;
+ }
+
+ return ActiveMQDestination::createDestination( type, dest );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string MarshalerHelper::convertMessageId( const Pointer<MessageId>& messageId ) {
+
+ std::string result = convertProducerId( messageId->getProducerId() ) + ":" +
+ Long::toString( messageId->getProducerSequenceId() );
+
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<MessageId> MarshalerHelper::convertMessageId( const std::string& messageId ) {
+
+ if( messageId == "" ) {
+ return Pointer<MessageId>();
+ }
+
+ Pointer<MessageId> id( new MessageId() );
+ StringTokenizer tokenizer( messageId, ":" );
+
+ id->setProducerId( convertProducerId( tokenizer.nextToken() ) );
+
+ while( tokenizer.hasMoreTokens() ){
+ std::string text = tokenizer.nextToken();
+ id->setProducerSequenceId( Long::parseLong( text ) );
+ }
+
+ return id;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string MarshalerHelper::convertConsumerId( const Pointer<ConsumerId>& consumerId ) {
+
+ return consumerId->getConnectionId() + ":" +
+ Long::toString( consumerId->getSessionId() ) + ":" +
+ Long::toString( consumerId->getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<ConsumerId> MarshalerHelper::convertConsumerId( const std::string& consumerId ) {
+
+ if( consumerId == "" ) {
+ return Pointer<ConsumerId>();
+ }
+
+ Pointer<ConsumerId> id( new ConsumerId() );
+ StringTokenizer tokenizer( consumerId, ":" );
+
+ id->setConnectionId( tokenizer.nextToken() );
+
+ while( tokenizer.hasMoreTokens() ){
+ string text = tokenizer.nextToken();
+
+ if( tokenizer.hasMoreTokens() ) {
+ id->setSessionId( Long::parseLong( text ) );
+ } else {
+ id->setValue( Long::parseLong( text ) );
+ }
+ }
+
+ return id;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string MarshalerHelper::convertProducerId( const Pointer<ProducerId>& producerId ) {
+
+ return producerId->getConnectionId() + ":" +
+ Long::toString( producerId->getSessionId() ) + ":" +
+ Long::toString( producerId->getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<ProducerId> MarshalerHelper::convertProducerId( const std::string& producerId ) {
+
+ if( producerId == "" ) {
+ return Pointer<ProducerId>();
+ }
+
+ Pointer<ProducerId> id( new ProducerId() );
+ StringTokenizer tokenizer( producerId, ":" );
+
+ id->setConnectionId( tokenizer.nextToken() );
+
+ while( tokenizer.hasMoreTokens() ){
+ string text = tokenizer.nextToken();
+
+ if( tokenizer.hasMoreTokens() ) {
+ id->setSessionId( Long::parseLong( text ) );
+ } else {
+ id->setValue( Long::parseLong( text ) );
+ }
+ }
+
+ return id;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string MarshalerHelper::convertTransactionId( const Pointer<TransactionId>& transactionId ) {
+
+ Pointer<LocalTransactionId> id = transactionId.dynamicCast<LocalTransactionId>();
+ std::string result = id->getConnectionId()->getValue() + ":" + Long::toString( id->getValue() );
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<TransactionId> MarshalerHelper::convertTransactionId( const std::string& transactionId ) {
+
+ if( transactionId == "" ) {
+ return Pointer<TransactionId>();
+ }
+
+ Pointer<LocalTransactionId> id( new LocalTransactionId() );
+ StringTokenizer tokenizer( transactionId, ":" );
+
+ Pointer<ConnectionId> connectionId( new ConnectionId() );
+ connectionId->setValue( tokenizer.nextToken() );
+ id->setConnectionId( connectionId );
+
+ while( tokenizer.hasMoreTokens() ){
+ string text = tokenizer.nextToken();
+ id->setValue( Long::parseLong( text ) );
+ }
+
+ return id;
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.h?rev=769604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.h Wed Apr 29 00:46:10 2009
@@ -0,0 +1,157 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_WIREFORMAT_STOMP_MARSHAL_MARSHALERHELPER_H_
+#define _ACTIVEMQ_WIREFORMAT_STOMP_MARSHAL_MARSHALERHELPER_H_
+
+#include <activemq/util/Config.h>
+#include <activemq/wireformat/stomp/StompFrame.h>
+#include <activemq/commands/Message.h>
+#include <activemq/commands/MessageId.h>
+#include <activemq/commands/ProducerId.h>
+#include <activemq/commands/ConsumerId.h>
+#include <activemq/commands/TransactionId.h>
+#include <activemq/commands/ActiveMQDestination.h>
+#include <decaf/lang/Pointer.h>
+
+namespace activemq {
+namespace wireformat {
+namespace stomp {
+namespace marshal {
+
+ using decaf::lang::Pointer;
+ using activemq::commands::Message;
+ using activemq::commands::MessageId;
+ using activemq::commands::ProducerId;
+ using activemq::commands::ConsumerId;
+ using activemq::commands::TransactionId;
+ using activemq::commands::ActiveMQDestination;
+
+ /**
+ * Utility Methods used when marshaling to and from StompFrame's.
+ *
+ * @since 3.0
+ */
+ class MarshalerHelper {
+ public:
+
+ MarshalerHelper() {}
+ virtual ~MarshalerHelper() {}
+
+ /**
+ * Converts the Headers in a Stomp Frame into Headers in the given Message
+ * Command.
+ *
+ * @param frame - The frame to extract headers from.
+ * @param message - The message to move the Headers to.
+ */
+ void convertProperties( const Pointer<StompFrame>& frame, const Pointer<Message>& message );
+
+ /**
+ * Converts the Properties in a Message Command to Valid Headers and Properties
+ * in the StompFrame.
+ *
+ * @param message - The message to move the Headers to.
+ * @param frame - The frame to extract headers from.
+ */
+ void convertProperties( const Pointer<Message>& message, const Pointer<StompFrame>& frame );
+
+ /**
+ * Converts from a Stomp Destination to an ActiveMQDestination
+ *
+ * @param destination - The Stomp Destination name string.
+ * @returns Pointer to a new ActiveMQDestination.
+ */
+ Pointer<ActiveMQDestination> convertDestination( const std::string& destination );
+
+ /**
+ * Converts from a ActiveMQDestination to a Stomp Destination Name
+ *
+ * @param destination - The ActiveMQDestination to Convert
+ * @return the Stomp String name that defines the destination.
+ */
+ std::string convertDestination( const Pointer<ActiveMQDestination>& destination );
+
+ /**
+ * Converts a MessageId instance to a Stomp MessageId String.
+ *
+ * @param messageId - the MessageId instance to convert.
+ * @return a Stomp Message Id String.
+ */
+ std::string convertMessageId( const Pointer<MessageId>& messageId );
+
+ /**
+ * Converts a Stomp MessageId string to a MessageId
+ *
+ * @param messageId - the String message Id to convert.
+ * @return Pointer to a new MessageId.
+ */
+ Pointer<MessageId> convertMessageId( const std::string& messageId );
+
+ /**
+ * Converts a ConsumerId instance to a Stomp ConsumerId String.
+ *
+ * @param ConsumerId - the Consumer instance to convert.
+ * @return a Stomp Consumer Id String.
+ */
+ std::string convertConsumerId( const Pointer<ConsumerId>& consumerId );
+
+ /**
+ * Converts a Stomp ConsumerId string to a ConsumerId
+ *
+ * @param ConsumerId - the String Consumer Id to convert.
+ * @return Pointer to a new ConsumerId.
+ */
+ Pointer<ConsumerId> convertConsumerId( const std::string& consumerId );
+
+ /**
+ * Converts a ProducerId instance to a Stomp ProducerId String.
+ *
+ * @param producerId - the Producer instance to convert.
+ * @return a Stomp Producer Id String.
+ */
+ std::string convertProducerId( const Pointer<ProducerId>& producerId );
+
+ /**
+ * Converts a Stomp ProducerId string to a ProducerId
+ *
+ * @param producerId - the String Producer Id to convert.
+ * @return Pointer to a new ProducerId.
+ */
+ Pointer<ProducerId> convertProducerId( const std::string& producerId );
+
+ /**
+ * Converts a TransactionId instance to a Stomp TransactionId String.
+ *
+ * @param transactionId - the Transaction instance to convert.
+ * @return a Stomp Transaction Id String.
+ */
+ std::string convertTransactionId( const Pointer<TransactionId>& transactionId );
+
+ /**
+ * Converts a Stomp TransactionId string to a TransactionId
+ *
+ * @param transactionId - the String Transaction Id to convert.
+ * @return Pointer to a new TransactionId.
+ */
+ Pointer<TransactionId> convertTransactionId( const std::string& transactionId );
+
+ };
+
+}}}}
+
+#endif /* _ACTIVEMQ_WIREFORMAT_STOMP_MARSHAL_MARSHALERHELPER_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/marshal/MarshalerHelper.h
------------------------------------------------------------------------------
svn:eol-style = native