activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r733507 - in /activemq/activemq-cpp/trunk/src/main/activemq/wireformat: ./ stomp/ stomp/marshal/
Date Sun, 11 Jan 2009 20:17:24 GMT
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 <vector>
+#include <decaf/io/IOException.h>
+#include <activemq/util/Config.h>
+
+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<char>& 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<unsigned char> 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 <string>
+#include <string.h>
+#include <map>
+#include <decaf/util/Properties.h>
+#include <activemq/util/Config.h>
+
+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<unsigned char>& getBody() const{
+            return body;
+        }
+
+        /**
+         * Non-const version of the body accessor.
+         */
+        std::vector<unsigned char>& 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<unsigned char> > 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<unsigned char> 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 <activemq/connector/stomp/commands/ConnectCommand.h>
+#include <activemq/connector/stomp/commands/ConnectedCommand.h>
+#include <activemq/connector/stomp/commands/SubscribeCommand.h>
+#include <activemq/connector/stomp/commands/UnsubscribeCommand.h>
+
+#include <decaf/util/UUID.h>
+
+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<transport::Command*>&
queue ){
+
+    const commands::ConnectCommand* connectCommand =
+        dynamic_cast<const commands::ConnectCommand*>( 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 <activemq/transport/mock/MockTransport.h>
+#include <activemq/util/Config.h>
+
+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<transport::Command*>&
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 <activemq/util/Config.h>
+#include <activemq/exceptions/ActiveMQException.h>
+
+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 <activemq/util/Config.h>
+#include <activemq/connector/stomp/StompFrame.h>
+#include <activemq/connector/stomp/marshal/MarshalException.h>
+
+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 <activemq/connector/stomp/marshal/Marshaler.h>
+
+#include <activemq/transport/Command.h>
+#include <activemq/connector/stomp/marshal/MarshalException.h>
+#include <activemq/connector/stomp/commands/CommandConstants.h>
+#include <activemq/connector/stomp/commands/AbstractCommand.h>
+#include <activemq/connector/stomp/StompFrame.h>
+
+// Commands we can receive
+#include <activemq/connector/stomp/commands/ConnectedCommand.h>
+#include <activemq/connector/stomp/commands/ReceiptCommand.h>
+#include <activemq/connector/stomp/commands/ErrorCommand.h>
+
+// Message Commands we can receive
+#include <activemq/connector/stomp/commands/MessageCommand.h>
+#include <activemq/connector/stomp/commands/BytesMessageCommand.h>
+#include <activemq/connector/stomp/commands/TextMessageCommand.h>
+
+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<Marshalable*>(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 <activemq/util/Config.h>
+#include <activemq/transport/Command.h>
+#include <activemq/connector/stomp/StompFrame.h>
+#include <activemq/connector/stomp/marshal/MarshalException.h>
+
+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



Mime
View raw message