Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 57198 invoked from network); 11 Jan 2009 20:17:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Jan 2009 20:17:49 -0000 Received: (qmail 82228 invoked by uid 500); 11 Jan 2009 20:17:49 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 82208 invoked by uid 500); 11 Jan 2009 20:17:49 -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 82199 invoked by uid 99); 11 Jan 2009 20:17:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Jan 2009 12:17:49 -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; Sun, 11 Jan 2009 20:17:45 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 94DBD2388988; Sun, 11 Jan 2009 12:17:24 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r733507 - in /activemq/activemq-cpp/trunk/src/main/activemq/wireformat: ./ stomp/ stomp/marshal/ Date: Sun, 11 Jan 2009 20:17:24 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090111201724.94DBD2388988@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Sun Jan 11 12:17:23 2009 New Revision: 733507 URL: http://svn.apache.org/viewvc?rev=733507&view=rev Log: https://issues.apache.org/activemq/browse/AMQCPP-100 Newly generated marshallers and the start of refactoring from connectors to wireformat used in the 3.0 version. Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/MarshalAware.h (with props) activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompFrame.h (with props) activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.cpp (with props) activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.h (with props) activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/MarshalException.h (with props) activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshalable.h (with props) activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp (with props) activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.h (with props) Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/MarshalAware.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/MarshalAware.h?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/MarshalAware.h (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/MarshalAware.h Sun Jan 11 12:17:23 2009 @@ -0,0 +1,98 @@ +/* + * 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_MARSHALAWARE_H_ +#define _ACTIVEMQ_WIREFORMAT_MARSHALAWARE_H_ + +#include +#include +#include + +namespace activemq{ +namespace wireformat{ + + class WireFormat; + + class AMQCPP_API MarshalAware { + public: + + virtual ~MarshalAware() {} + + /** + * Determine if the class implementing this interface is really + * wanting to be told about marshaling. Normally if you didn't + * want to be marshal aware you just wouldn't implement this interface + * but since this is C++ and we don't have true interfaces we need + * a flat inheritance hierarchy, so we always implement this. + * @returns true if this class cares about marshaling. + */ + virtual bool isMarshalAware() const = 0; + + /** + * Called before marshaling is started to prepare the object to be + * marshaled. + * @param wireFormat - the wireformat object to control marshaling + */ + virtual void beforeMarshal( WireFormat* wireFormat ) + throw ( decaf::io::IOException ) = 0; + + /** + * Called after marshaling is started to cleanup the object being + * marshaled. + * @param wireFormat - the wireformat object to control marshaling + */ + virtual void afterMarshal( WireFormat* wireFormat ) + throw ( decaf::io::IOException ) = 0; + + /** + * Called before unmarshaling is started to prepare the object to be + * unmarshaled. + * @param wireFormat - the wireformat object to control unmarshaling + */ + virtual void beforeUnmarshal( WireFormat* wireFormat ) + throw ( decaf::io::IOException ) = 0; + + /** + * Called after unmarshaling is started to cleanup the object being + * unmarshaled. + * @param wireFormat - the wireformat object to control unmarshaling + */ + virtual void afterUnmarshal( WireFormat* wireFormat ) + throw ( decaf::io::IOException ) = 0; + + /** + * Called to set the data to this object that will contain the objects + * marshaled form. + * @param wireFormat - the wireformat object to control unmarshaling + * @param data - vector of object binary data + */ + virtual void setMarshaledForm( WireFormat* wireFormat, + const std::vector& data ) = 0; + + /** + * Called to get the data to this object that will contain the objects + * marshaled form. + * @param wireFormat - the wireformat object to control unmarshaling + * @return buffer that holds the objects data. + */ + virtual std::vector getMarshaledForm( WireFormat* wireFormat ) = 0; + + }; + +}} + +#endif /*_ACTIVEMQ_WIREFORMAT_MARSHALAWARE_H_*/ Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/MarshalAware.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompFrame.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompFrame.h?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompFrame.h (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompFrame.h Sun Jan 11 12:17:23 2009 @@ -0,0 +1,145 @@ +/* + * 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_CONNECTOR_STOMP_STOMPFRAMEWRAPPER_H_ +#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPFRAMEWRAPPER_H_ + +#include +#include +#include +#include +#include + +namespace activemq{ +namespace connector{ +namespace stomp{ + + /** + * A Stomp-level message frame that encloses all messages + * to and from the broker. + */ + class AMQCPP_API StompFrame{ + public: + + /** + * Default constructor. + */ + StompFrame(){} + + /** + * Destruction. + */ + virtual ~StompFrame() {} + + /** + * Clonse this message exactly, returns a new instance that the + * caller is required to delete. + * @return new copy of this message + */ + virtual StompFrame* clone() const { + StompFrame* frame = new StompFrame(); + frame->copy( this ); + return frame; + } + + /** + * Copies the contents of the passed Frame to this one + * @param src - Frame to copy + */ + virtual void copy( const StompFrame* src ) { + + this->setCommand( src->getCommand() ); + this->properties.copy( &( src->getProperties() ) ); + // Use the Vectors assignment operator. + this->body = src->getBody(); + } + + /** + * Sets the command for this stomp frame. + * @param cmd command The command to be set. + */ + void setCommand( const std::string& cmd ){ + this->command = cmd; + } + + /** + * Accessor for this frame's command field. + */ + const std::string& getCommand() const{ + return command; + } + + /** + * Gets access to the header properties for this frame. + * @return the Properties object owned by this Frame + */ + decaf::util::Properties& getProperties(){ return properties; } + const decaf::util::Properties& getProperties() const { + return properties; + } + + /** + * Accessor for the body data of this frame. + * @return char pointer to body data + */ + const std::vector& getBody() const{ + return body; + } + + /** + * Non-const version of the body accessor. + */ + std::vector& getBody(){ + return body; + } + + /** + * Return the number of bytes contained in this frames body + * @return Body bytes length. + */ + std::size_t getBodyLength() const{ return body.size(); } + + /** + * Sets the body data of this frame as a byte sequence. + * @param bytes The byte buffer to be set in the body. + * @param numBytes The number of bytes in the buffer. + */ + void setBody( const unsigned char* bytes, std::size_t numBytes ){ + + // Remove old data + body.clear(); + + // Copy data to internal buffer. + std::back_insert_iterator< std::vector > iter( body ); + std::copy( bytes, bytes + numBytes, iter ); + } + + private: + + // String Name of this command. + std::string command; + + // Properties of the Stomp Message + decaf::util::Properties properties; + + // Byte data of Body. + std::vector body; + }; + +}}} + +#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPFRAMEWRAPPER_H_*/ Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompFrame.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.cpp?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.cpp (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.cpp Sun Jan 11 12:17:23 2009 @@ -0,0 +1,68 @@ +/* + * 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 "StompResponseBuilder.h" + +#include +#include +#include +#include + +#include + +using namespace activemq; +using namespace activemq::wireformat; +using namespace activemq::wireformat::stomp; +using namespace activemq::transport; +using namespace activemq::transport::mock; +using namespace decaf; +using namespace decaf::util; + +//////////////////////////////////////////////////////////////////////////////// +Response* StompResponseBuilder::buildResponse( const transport::Command* cmd ){ + + // If this command requires a response we don't know what it is + // so we throw an exception. + if( cmd->isResponseRequired() ) { + + throw transport::CommandIOException( __FILE__, __LINE__, + "StompResponseBuilder - unrecognized command" ); + } + + return NULL; +} + +//////////////////////////////////////////////////////////////////////////////// +void StompResponseBuilder::buildIncomingCommands( + const transport::Command* command, decaf::util::Queue& queue ){ + + const commands::ConnectCommand* connectCommand = + dynamic_cast( command ); + + if( connectCommand != NULL ) { + commands::ConnectedCommand* resp = new commands::ConnectedCommand(); + resp->setCorrelationId( connectCommand->getCommandId() ); + + if( connectCommand->getClientId() == NULL ) { + resp->setSessionId( UUID::randomUUID().toString() ); + } else { + resp->setSessionId( connectCommand->getClientId() ); + } + + queue.push( resp ); + } +} Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.h?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.h (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.h Sun Jan 11 12:17:23 2009 @@ -0,0 +1,43 @@ +/* + * 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_STOMPRESPONSEBUILDER_H_ +#define _ACTIVEMQ_WIREFORMAT_STOMP_STOMPRESPONSEBUILDER_H_ + +#include +#include + +namespace activemq{ +namespace wireformat{ +namespace stomp{ + + class AMQCPP_API StompResponseBuilder : + public transport::mock::MockTransport::ResponseBuilder{ + public: + + StompResponseBuilder() {} + virtual ~StompResponseBuilder() {} + + virtual transport::Response* buildResponse( const transport::Command* cmd ); + virtual void buildIncomingCommands( + const transport::Command* cmd, decaf::util::Queue& queue ); + + }; + +}}} + +#endif /*_ACTIVEMQ_WIREFORMAT_STOMP_STOMPRESPONSEBUILDER_H_*/ Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/StompResponseBuilder.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/MarshalException.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/MarshalException.h?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/MarshalException.h (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/MarshalException.h Sun Jan 11 12:17:23 2009 @@ -0,0 +1,122 @@ +/* + * 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_CONNECTOR_STOMP_MARSHALL_MARSHALEXCEPTION_H_ +#define _ACTIVEMQ_CONNECTOR_STOMP_MARSHALL_MARSHALEXCEPTION_H_ + +#include +#include + +namespace activemq{ +namespace connector{ +namespace stomp{ +namespace marshal{ + + /* + * Signals that an problem occurred during marshalling. + */ + class AMQCPP_API MarshalException : public exceptions::ActiveMQException { + public: + + /** + * Default Constructor + */ + MarshalException() throw() {} + + /** + * Copy Constructor + * @param ex the exception to copy + */ + MarshalException( const exceptions::ActiveMQException& ex ) throw() + : exceptions::ActiveMQException() { + *(ActiveMQException*)this = ex; + } + + /** + * Copy Constructor + * @param ex the exception to copy, which is an instance of this type + */ + MarshalException( const MarshalException& ex ) throw() + : exceptions::ActiveMQException() { + *(exceptions::ActiveMQException*)this = ex; + } + + /** + * Constructor - Initializes the file name and line number where + * this message occurred. Sets the message to report, using an + * optional list of arguments to parse into the message + * @param file name where exception occurs + * @param line number where the exception occurred. + * @param cause The exception that was the cause for this one to be thrown. + * @param message to report + * @param list of primitives that are formatted into the message + */ + MarshalException( const char* file, const int lineNumber, + const std::exception* cause, + const char* msg, ... ) + throw() : exceptions::ActiveMQException( cause ) + { + va_list vargs; + va_start( vargs, msg ); + buildMessage( msg, vargs ); + + // Set the first mark for this exception. + setMark( file, lineNumber ); + } + + /** + * Constructor + * @param cause Pointer to the exception that caused this one to + * be thrown, the object is cloned caller retains ownership. + */ + MarshalException( const std::exception* cause ) + throw() : exceptions::ActiveMQException( cause ) {} + + /** + * Constructor + * @param file name of the file were the exception occurred. + * @param lineNumber line where the exception occurred + * @param msg the message that was generated + */ + MarshalException( const char* file, + const int lineNumber, + const char* msg, ...) throw() + : exceptions::ActiveMQException() { + + va_list vargs ; + va_start(vargs, msg) ; + buildMessage(msg, vargs) ; + + // Set the first mark for this exception. + setMark( file, lineNumber ); + } + + /** + * Clones this exception. This is useful for cases where you need + * to preserve the type of the original exception as well as the message. + * All subclasses should override. + */ + virtual MarshalException* clone() const{ + return new MarshalException( *this ); + } + + virtual ~MarshalException() throw() {} + + }; + +}}}} + +#endif /*_ACTIVEMQ_CONNECTOR_STOMP_MARSHAL_MARSHALLEXCEPTION_H_*/ Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/MarshalException.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshalable.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshalable.h?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshalable.h (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshalable.h Sun Jan 11 12:17:23 2009 @@ -0,0 +1,49 @@ +/* + * 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_CONNECTOR_STOMP_MARSHAL_MARSHALABLE_H_ +#define _ACTIVEMQ_CONNECTOR_STOMP_MARSHAL_MARSHALABLE_H_ + +#include +#include +#include + +namespace activemq{ +namespace connector{ +namespace stomp{ +namespace marshal{ + + class AMQCPP_API Marshalable { + public: + + virtual ~Marshalable(void) {} + + /** + * Marshals the command to a stomp frame. + * @returns the stomp frame representation of this + * command. + * @throws MarshalException if the command is not + * in a state that can be marshalled. + */ + virtual const StompFrame& marshal(void) + throw ( marshal::MarshalException ) = 0; + + }; + +}}}} + +#endif /*_ACTIVEMQ_CONNECTOR_STOMP_MARSHAL_MARSHALABLE_H_*/ Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshalable.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp Sun Jan 11 12:17:23 2009 @@ -0,0 +1,112 @@ +/* + * 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 + +#include +#include +#include +#include +#include + +// Commands we can receive +#include +#include +#include + +// Message Commands we can receive +#include +#include +#include + +using namespace activemq; +using namespace activemq::exceptions; +using namespace activemq::transport; +using namespace activemq::connector::stomp; +using namespace activemq::connector::stomp::commands; +using namespace activemq::connector::stomp::marshal; +using namespace decaf::lang; + +//////////////////////////////////////////////////////////////////////////////// +transport::Command* Marshaler::marshal( StompFrame* frame ) + throw ( MarshalException ) { + + try { + + CommandConstants::CommandId commandId = + CommandConstants::toCommandId(frame->getCommand().c_str()); + transport::Command* command = NULL; + + if(commandId == CommandConstants::CONNECTED){ + command = new ConnectedCommand( frame ); + } + else if(commandId == CommandConstants::ERROR_CMD){ + command = new ErrorCommand( frame ); + } + else if(commandId == CommandConstants::RECEIPT){ + command = new ReceiptCommand( frame ); + } + else if(commandId == CommandConstants::MESSAGE){ + + if( !frame->getProperties().hasProperty( + CommandConstants::toString( + CommandConstants::HEADER_CONTENTLENGTH ) ) ) { + command = new TextMessageCommand( frame ); + } else { + command = new BytesMessageCommand( frame ); + } + } + + // We either got a command or a response, but if we got neither + // then complain, something went wrong. + if(command == NULL) { + throw MarshalException( + __FILE__, __LINE__, + "Marshaler::marshal - No Command Created from frame"); + } + + return command; + } + AMQ_CATCH_RETHROW( MarshalException ) + AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, MarshalException ) + AMQ_CATCH_EXCEPTION_CONVERT( Exception, MarshalException ) + AMQ_CATCHALL_THROW( MarshalException ) +} + +//////////////////////////////////////////////////////////////////////////////// +const StompFrame& Marshaler::marshal( transport::Command* command ) + throw ( MarshalException ) { + + try{ + + Marshalable* marshalable = + dynamic_cast(command); + + // Easy, just get the frame from the command + if( marshalable != NULL ) { + return marshalable->marshal(); + } else { + throw MarshalException( + __FILE__, __LINE__, + "Marshaler::marshal - Invalid Command Type!"); + } + } + AMQ_CATCH_RETHROW( MarshalException ) + AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, MarshalException ) + AMQ_CATCH_EXCEPTION_CONVERT( Exception, MarshalException ) + AMQ_CATCHALL_THROW( MarshalException ) +} Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.h?rev=733507&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.h (added) +++ activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.h Sun Jan 11 12:17:23 2009 @@ -0,0 +1,67 @@ +/* + * 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_CONNECTOR_STOMP_MARSHALER_H_ +#define _ACTIVEMQ_CONNECTOR_STOMP_MARSHALER_H_ + +#include +#include +#include +#include + +namespace activemq{ +namespace connector{ +namespace stomp{ +namespace marshal{ + + /** + * Interface for all marshallers between Commands and + * stomp frames. + */ + class AMQCPP_API Marshaler { + public: + + Marshaler(void) {} + virtual ~Marshaler(void) {} + + /** + * Marshall a Stomp Frame to a Stomp Command, the frame is now + * owned by this Command, caller should not use the frame again. + * @param frame Frame to Marshall + * @return Newly Marshaled Stomp Message + * @throws MarshalException + */ + virtual transport::Command* marshal( StompFrame* frame ) + throw ( MarshalException ); + + /** + * Marshal a Stomp Command to a Stom Frame, if the command that + * is past is not castable to a Stomp Command an Exception will + * be thrown + * @param command The Stomp Command to Marshal + * @return newly Marshaled Stomp Frame + * @throws MarshalException + */ + virtual const StompFrame& marshal( + transport::Command* command ) + throw ( MarshalException ); + + }; + +}}}} + +#endif /*_ACTIVEMQ_CONNECTOR_STOMP_MARSHALER_H_*/ Propchange: activemq/activemq-cpp/trunk/src/main/activemq/wireformat/stomp/marshal/Marshaler.h ------------------------------------------------------------------------------ svn:eol-style = native