diff --git a/openwire-cpp/.classpath b/openwire-cpp/.classpath new file mode 100644 index 0000000000..233be1d2c4 --- /dev/null +++ b/openwire-cpp/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/openwire-cpp/.project b/openwire-cpp/.project new file mode 100644 index 0000000000..0676cbc96e --- /dev/null +++ b/openwire-cpp/.project @@ -0,0 +1,17 @@ + + + openwire-cpp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/openwire-cpp/src/IBytesMessage.hpp b/openwire-cpp/src/IBytesMessage.hpp new file mode 100644 index 0000000000..3c30961d5a --- /dev/null +++ b/openwire-cpp/src/IBytesMessage.hpp @@ -0,0 +1,73 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 IBytesMessage_hpp_ +#define IBytesMessage_hpp_ + +// Turn off warning message for ignored exception specification +#ifdef _MSC_VER +#pragma warning( disable : 4290 ) +#endif + +#include +#include "IMessage.hpp" +#include "MessageEOFException.hpp" +#include "MessageNotReadableException.hpp" +#include "MessageNotWritableException.hpp" +#include "util/ifr/p" + +namespace apache +{ + namespace activemq + { + namespace client + { + using namespace std; + using namespace ifr; + +/* + * + */ +struct IBytesMessage //: IMessage +{ + virtual int getBodyLength() = 0; + virtual void reset() = 0 ; + virtual char readByte() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual int readBytes(char* buffer, int length) throw (MessageNotReadableException) = 0 ; + virtual bool readBoolean() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual double readDouble() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual float readFloat() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual int readInt() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual long long readLong() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual short readShort() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual p readUTF() throw (MessageNotReadableException, MessageEOFException) = 0 ; + virtual void writeBoolean(bool value) throw (MessageNotWritableException) = 0 ; + virtual void writeByte(char value) throw (MessageNotWritableException) = 0 ; + virtual void writeBytes(char* value, int length) throw (MessageNotWritableException) = 0 ; + virtual void writeDouble(double value) throw (MessageNotWritableException) = 0 ; + virtual void writeFloat(float value) throw (MessageNotWritableException) = 0 ; + virtual void writeInt(int value) throw (MessageNotWritableException) = 0 ; + virtual void writeLong(long long value) throw (MessageNotWritableException) = 0 ; + virtual void writeShort(short value) throw (MessageNotWritableException) = 0 ; + virtual void writeUTF(p value) throw (MessageNotWritableException) = 0 ; +} ; + +/* namespace */ + } + } +} + +#endif /*IBytesMessage_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/IllegalArgumentException.hpp b/openwire-cpp/src/IllegalArgumentException.hpp new file mode 100644 index 0000000000..e4b5530fa2 --- /dev/null +++ b/openwire-cpp/src/IllegalArgumentException.hpp @@ -0,0 +1,49 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 IllegalArgumentException_hpp_ +#define IllegalArgumentException_hpp_ + +#include "TraceException.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + using namespace std ; + +/* + * Signals that a method has been passed an illegal or inappropriate argument. + */ +class IllegalArgumentException : public TraceException +{ +public: + IllegalArgumentException() : TraceException() + { /* no-op */ } ; + IllegalArgumentException(const char *const& msg) : TraceException(msg) + { /* no-op */ } ; + IllegalArgumentException(const char* fileName, int lineNo, const char* msg) : TraceException(msg) + { /* no-op */ } ; +} ; + +/* namespace */ + } + } +} + +#endif /*IllegalArgumentException_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/MessageEOFException.hpp b/openwire-cpp/src/MessageEOFException.hpp new file mode 100644 index 0000000000..8ea3945a24 --- /dev/null +++ b/openwire-cpp/src/MessageEOFException.hpp @@ -0,0 +1,50 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 MessageEOFException_hpp_ +#define MessageEOFException_hpp_ + +#include "TraceException.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + using namespace std ; + +/* + * Signals that an unexpected end of stream has been reached when reading + * a message. + */ +class MessageEOFException : public TraceException +{ +public: + MessageEOFException() : TraceException() + { /* no-op */ } ; + MessageEOFException(const char *const& msg) : TraceException(msg) + { /* no-op */ } ; + MessageEOFException(const char* fileName, int lineNo, const char* msg) : TraceException(msg) + { /* no-op */ } ; +} ; + +/* namespace */ + } + } +} + +#endif /*MessageEOFException_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/MessageFormatException.hpp b/openwire-cpp/src/MessageFormatException.hpp new file mode 100644 index 0000000000..7c2cd862d5 --- /dev/null +++ b/openwire-cpp/src/MessageFormatException.hpp @@ -0,0 +1,50 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 MessageFormatException_hpp_ +#define MessageFormatException_hpp_ + +#include "TraceException.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + using namespace std ; + +/* + * Signals that a client attempts to use a data type not supported by a + * message or attempts to read data in a message as the wrong type. + */ +class MessageFormatException : public TraceException +{ +public: + MessageFormatException() : TraceException() + { /* no-op */ } ; + MessageFormatException(const char *const& msg) : TraceException(msg) + { /* no-op */ } ; + MessageFormatException(const char* fileName, int lineNo, const char* msg) : TraceException(msg) + { /* no-op */ } ; +} ; + +/* namespace */ + } + } +} + +#endif /*MessageFormatException_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/MessageNotReadableException.hpp b/openwire-cpp/src/MessageNotReadableException.hpp new file mode 100644 index 0000000000..11f14c9254 --- /dev/null +++ b/openwire-cpp/src/MessageNotReadableException.hpp @@ -0,0 +1,49 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 MessageNotReadableException_hpp_ +#define MessageNotReadableException_hpp_ + +#include "TraceException.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + using namespace std ; + +/* + * Signals that a message is in read-only mode. + */ +class MessageNotReadableException : public TraceException +{ +public: + MessageNotReadableException() : TraceException() + { /* no-op */ } ; + MessageNotReadableException(const char *const& msg) : TraceException(msg) + { /* no-op */ } ; + MessageNotReadableException(const char* fileName, int lineNo, const char* msg) : TraceException(msg) + { /* no-op */ } ; +} ; + +/* namespace */ + } + } +} + +#endif /*MessageNotReadableException_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/MessageNotWritableException.hpp b/openwire-cpp/src/MessageNotWritableException.hpp new file mode 100644 index 0000000000..66944092cf --- /dev/null +++ b/openwire-cpp/src/MessageNotWritableException.hpp @@ -0,0 +1,49 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 MessageNotWritableException_hpp_ +#define MessageNotWritableException_hpp_ + +#include "TraceException.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + using namespace std ; + +/* + * Signals that a message is in read-only mode. + */ +class MessageNotWritableException : public TraceException +{ +public: + MessageNotWritableException() : TraceException() + { /* no-op */ } ; + MessageNotWritableException(const char *const& msg) : TraceException(msg) + { /* no-op */ } ; + MessageNotWritableException(const char* fileName, int lineNo, const char* msg) : TraceException(msg) + { /* no-op */ } ; +} ; + +/* namespace */ + } + } +} + +#endif /*MessageNotWritableException_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/command/ActiveMQBytesMessage.cpp b/openwire-cpp/src/command/ActiveMQBytesMessage.cpp new file mode 100644 index 0000000000..04c1510719 --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQBytesMessage.cpp @@ -0,0 +1,402 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 "command/ActiveMQBytesMessage.hpp" + +using namespace apache::activemq::client::command; + +/* + * + */ +ActiveMQBytesMessage::ActiveMQBytesMessage() +{ + this->body = new char[INITIAL_SIZE] ; + this->bodySize = INITIAL_SIZE ; + this->bodyLength = 0 ; + this->offset = 0 ; + this->readMode = false ; +} + +/* + * + */ +ActiveMQBytesMessage::~ActiveMQBytesMessage() +{ +} + +/* + * + */ +int ActiveMQBytesMessage::getCommandType() +{ + return ActiveMQBytesMessage::TYPE ; +} + +/* + * + */ +int ActiveMQBytesMessage::getBodyLength() +{ + return bodyLength ; +} + +/* + * + */ +void ActiveMQBytesMessage::reset() +{ + readMode = true ; + offset = 0 ; +} + +/* + * + */ +char ActiveMQBytesMessage::readByte() throw(MessageNotReadableException, MessageEOFException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + // Check for EOF offset + if( offset > bodySize ) + throw MessageEOFException() ; + + // Read a single byte + return body[offset++] ; +} + +/* + * + */ +int ActiveMQBytesMessage::readBytes(char* buffer, int length) throw (MessageNotReadableException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + // Check for EOF offset + if( offset > bodySize ) + return -1 ; + + // Copy bytes to supplied buffer + for( int i = 0 ; i < length ; i++, offset++ ) + { + // Check for body EOF + if( offset > bodySize ) + return i ; + + buffer[i] = body[offset] ; + } + return length ; +} + +/* + * + */ +bool ActiveMQBytesMessage::readBoolean() throw(MessageNotReadableException, MessageEOFException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + bool value ; + int result ; + + // Read a boolean + result = readBytes((char*)&value, sizeof(bool)) ; + + // Check for EOF offset + if( result == -1 || result < sizeof(bool) ) + throw MessageEOFException() ; + + return value ; +} + +/* + * + */ +double ActiveMQBytesMessage::readDouble() throw(MessageNotReadableException, MessageEOFException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + double value ; + int result ; + + // Read a double + result = readBytes((char*)&value, sizeof(double)) ; + + // Check for EOF offset + if( result == -1 || result < sizeof(double) ) + throw MessageEOFException() ; + + // Convert from big endian to little endian if necessary + return ntohd(value) ; +} + +/* + * + */ +float ActiveMQBytesMessage::readFloat() throw(MessageNotReadableException, MessageEOFException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + float value ; + int result ; + + // Read a float + result = readBytes((char*)&value, sizeof(float)) ; + + // Check for EOF offset + if( result == -1 || result < sizeof(float) ) + throw MessageEOFException() ; + + // Convert from big endian to little endian if necessary + return ntohf(value) ; +} + +/* + * + */ +short ActiveMQBytesMessage::readShort() throw(MessageNotReadableException, MessageEOFException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + short value ; + int result ; + + // Read a short + result = readBytes((char*)&value, sizeof(short)) ; + + // Check for EOF offset + if( result == -1 || result < sizeof(short) ) + throw MessageEOFException() ; + + // Convert from big endian to little endian if necessary + return ntohs(value) ; +} + +/* + * + */ +int ActiveMQBytesMessage::readInt() throw(MessageNotReadableException, MessageEOFException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + int value ; + int result ; + + // Read an integer + result = readBytes((char*)&value, sizeof(int)) ; + + // Check for EOF offset + if( result == -1 || result < sizeof(int) ) + throw MessageEOFException() ; + + // Convert from big endian to little endian if necessary + return ntohi(value) ; +} + +/* + * + */ +long long ActiveMQBytesMessage::readLong() throw(MessageNotReadableException, MessageEOFException) +{ + // Assert read mode + if( !readMode ) + throw MessageNotReadableException() ; + + long long value ; + int result ; + + // Read a long long + result = readBytes((char*)&value, sizeof(long long)) ; + + // Check for EOF offset + if( result == -1 || result < sizeof(long long) ) + throw MessageEOFException() ; + + // Convert from big endian to little endian if necessary + return ntohl(value) ; +} + +/* + * + */ +p ActiveMQBytesMessage::readUTF() throw(MessageNotReadableException, MessageEOFException) +{ + // TODO + return NULL ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeByte(char value) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Check for EOF offset + if( offset > bodySize ) + expandBody() ; + + // Write a single byte + body[offset++] = value ; + + // Update content length + bodyLength = offset ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeBytes(char* value, int length) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Copy bytes from supplied buffer + for( int i = 0 ; i < length ; i++, offset++ ) + { + // Check for EOF offset + if( offset > bodySize ) + expandBody() ; + + body[offset] = value[i] ; + } + // Update content length + bodyLength = offset ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeBoolean(bool value) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Write boolean + writeBytes((char*)&value, sizeof(bool)) ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeDouble(double v) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Write double, convert from little endian to big endian if necessary + double value = htond(v) ; + writeBytes((char*)&value, sizeof(double)) ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeFloat(float v) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Write float, convert from little endian to big endian if necessary + float value = htonf(v) ; + writeBytes((char*)&value, sizeof(float)) ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeInt(int v) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Write integer, convert from little endian to big endian if necessary + int value = htoni(v) ; + writeBytes((char*)&value, sizeof(int)) ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeLong(long long v) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Write long, convert from little endian to big endian if necessary + long long value = htonl(v) ; + writeBytes((char*)&value, sizeof(long long)) ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeShort(short v) throw (MessageNotWritableException) +{ + // Assert write mode + if( readMode ) + throw MessageNotWritableException() ; + + // Write short, convert from little endian to big endian if necessary + short value = htons(v) ; + writeBytes((char*)&value, sizeof(short)) ; +} + +/* + * + */ +void ActiveMQBytesMessage::writeUTF(p value) throw (MessageNotWritableException) +{ + // TODO +} + +/* + * + */ +void ActiveMQBytesMessage::expandBody() +{ + char* newBody ; + int newSize = bodySize + ActiveMQBytesMessage::EXPAND_SIZE ; + + // Create new body and copy current contents + newBody = new char[ newSize ] ; + memcpy(newBody, body, bodySize) ; + + // Clean up and use new content body + delete [] body ; + body = newBody ; + bodySize = newSize ; +} diff --git a/openwire-cpp/src/command/ActiveMQBytesMessage.hpp b/openwire-cpp/src/command/ActiveMQBytesMessage.hpp new file mode 100644 index 0000000000..40dacb17d2 --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQBytesMessage.hpp @@ -0,0 +1,102 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 ActiveMQBytesMessage_hpp_ +#define ActiveMQBytesMessage_hpp_ + +// Turn off warning message for ignored exception specification +#ifdef _MSC_VER +#pragma warning( disable : 4290 ) +#endif + +#include +#include +#include "IBytesMessage.hpp" +#include "ActiveMQMessage.hpp" +#include "MessageEOFException.hpp" +#include "MessageNotWritableException.hpp" +#include "util/Endian.hpp" +#include "util/ifr/ap" +#include "util/ifr/p" +#include "util/MapItemHolder.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + namespace command + { + using namespace ifr; + using namespace apache::activemq::client::util; + +/* + * + */ +class ActiveMQBytesMessage : public ActiveMQMessage, IBytesMessage +{ +private: + char* body ; + int bodySize, + bodyLength, + offset ; + bool readMode ; + + const static int INITIAL_SIZE = 512 ; + const static int EXPAND_SIZE = 128 ; + +public: + const static int TYPE = 24 ; + +public: + ActiveMQBytesMessage() ; + virtual ~ActiveMQBytesMessage() ; + + virtual int getCommandType() ; + virtual int getBodyLength() ; + + virtual void reset() ; + virtual char readByte() throw (MessageNotReadableException, MessageEOFException) ; + virtual int readBytes(char* buffer, int length) throw (MessageNotReadableException) ; + virtual bool readBoolean() throw (MessageNotReadableException, MessageEOFException) ; + virtual double readDouble() throw (MessageNotReadableException, MessageEOFException) ; + virtual float readFloat() throw (MessageNotReadableException, MessageEOFException) ; + virtual int readInt() throw (MessageNotReadableException, MessageEOFException) ; + virtual long long readLong() throw (MessageNotReadableException, MessageEOFException) ; + virtual short readShort() throw (MessageNotReadableException, MessageEOFException) ; + virtual p readUTF() throw (MessageNotReadableException, MessageEOFException) ; + virtual void writeBoolean(bool value) throw (MessageNotWritableException) ; + virtual void writeByte(char value) throw (MessageNotWritableException) ; + virtual void writeBytes(char* value, int length) throw (MessageNotWritableException) ; + virtual void writeDouble(double value) throw (MessageNotWritableException) ; + virtual void writeFloat(float value) throw (MessageNotWritableException) ; + virtual void writeInt(int value) throw (MessageNotWritableException) ; + virtual void writeLong(long long value) throw (MessageNotWritableException) ; + virtual void writeShort(short value) throw (MessageNotWritableException) ; + virtual void writeUTF(p value) throw (MessageNotWritableException) ; + +private: + void expandBody() ; +} ; + +/* namespace */ + } + } + } +} + +#endif /*ActiveMQBytesMessage_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/command/ActiveMQMapMessage.cpp b/openwire-cpp/src/command/ActiveMQMapMessage.cpp new file mode 100644 index 0000000000..f0cdec9c14 --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQMapMessage.cpp @@ -0,0 +1,441 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 "command/ActiveMQMapMessage.hpp" + +using namespace apache::activemq::client::command; + +/* + * + */ +ActiveMQMapMessage::ActiveMQMapMessage() +{ +} + +/* + * + */ +ActiveMQMapMessage::~ActiveMQMapMessage() +{ +} + +/* + * + */ +int ActiveMQMapMessage::getCommandType() +{ + return ActiveMQMapMessage::TYPE ; +} + +/* + * + */ +bool ActiveMQMapMessage::getBoolean(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No boolean value available for given key") ; + + try + { + // Try to get value as a boolean + return tempIter->second->getBoolean() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setBoolean(const char* name, bool value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +char ActiveMQMapMessage::getByte(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No byte value available for given key") ; + + try + { + // Try to get value as a byte + return tempIter->second->getByte() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setByte(const char* name, char value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +ap ActiveMQMapMessage::getBytes(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No byte array value available for given key") ; + + try + { + // Try to get value as a byte array + return tempIter->second->getBytes() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setBytes(const char* name, ap value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +double ActiveMQMapMessage::getDouble(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No double value available for given key") ; + + try + { + // Try to get value as a double + return tempIter->second->getDouble() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setDouble(const char* name, double value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +float ActiveMQMapMessage::getFloat(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No float value available for given key") ; + + try + { + // Try to get value as a float + return tempIter->second->getFloat() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setFloat(const char* name, float value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +int ActiveMQMapMessage::getInt(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No integer value available for given key") ; + + try + { + // Try to get value as an integer + return tempIter->second->getInt() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setInt(const char* name, int value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +long long ActiveMQMapMessage::getLong(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No long value available for given key") ; + + try + { + // Try to get value as a long + return tempIter->second->getLong() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setLong(const char* name, long long value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +short ActiveMQMapMessage::getShort(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No short value available for given key") ; + + try + { + // Try to get value as a short + return tempIter->second->getShort() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setShort(const char* name, short value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +p ActiveMQMapMessage::getString(const char* name) throw (MessageFormatException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + if( tempIter == contentMap.end() ) + throw MessageFormatException("No short value available for given key") ; + + try + { + // Try to get value as a string + return tempIter->second->getString() ; + } + catch( ConversionException ce ) + { + throw MessageFormatException( ce.what() ) ; + } +} + +/* + * + */ +void ActiveMQMapMessage::setString(const char* name, p value) throw (IllegalArgumentException) +{ + // Assert arguments + if( name == NULL || strcmp(name, "") == 0 ) + throw IllegalArgumentException("Invalid key name") ; + + p key = new string(name) ; + contentMap[key] = new MapItemHolder(value) ; +} + +/* + * + */ +ap ActiveMQMapMessage::getMapNames() +{ + map< p, p >::const_iterator tempIter ; + ap keyNames (contentMap.size()) ; + int index = 0 ; + + for( tempIter = contentMap.begin() ; + tempIter != contentMap.end() ; + tempIter++ ) + { + keyNames[index++] = tempIter->first ; + } + return keyNames ; +} + +/* + * + */ +bool ActiveMQMapMessage::itemExists(const char* name) +{ + map< p, p >::const_iterator tempIter ; + p key = new string(name) ; + + // Check if key exists in map + tempIter = contentMap.find(key) ; + return ( tempIter != contentMap.end() ) ? true : false ; +} diff --git a/openwire-cpp/src/command/ActiveMQMapMessage.hpp b/openwire-cpp/src/command/ActiveMQMapMessage.hpp new file mode 100644 index 0000000000..6cef57cf4a --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQMapMessage.hpp @@ -0,0 +1,91 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 ActiveMQMapMessage_hpp_ +#define ActiveMQMapMessage_hpp_ + +// Turn off warning message for ignored exception specification +#ifdef _MSC_VER +#pragma warning( disable : 4290 ) +#endif + +#include +#include +#include "ActiveMQMessage.hpp" +#include "IllegalArgumentException.hpp" +#include "MessageFormatException.hpp" +#include "util/ifr/ap" +#include "util/ifr/p" +#include "util/MapItemHolder.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + namespace command + { + using namespace ifr; + using namespace apache::activemq::client::util; + +/* + * + */ +class ActiveMQMapMessage : public ActiveMQMessage +{ +private: + p text ; + map< p, p > contentMap ; + +public: + const static int TYPE = 25 ; + +public: + ActiveMQMapMessage() ; + virtual ~ActiveMQMapMessage() ; + + virtual int getCommandType() ; + + virtual bool getBoolean(const char* name) throw (MessageFormatException) ; + virtual void setBoolean(const char* name, bool value) throw (IllegalArgumentException) ; + virtual char getByte(const char* name) throw (MessageFormatException) ; + virtual void setByte(const char* name, char value) throw (IllegalArgumentException) ; + virtual ap getBytes(const char* name) throw (MessageFormatException) ; + virtual void setBytes(const char* name, ap value) throw (IllegalArgumentException) ; + virtual double getDouble(const char* name) throw (MessageFormatException) ; + virtual void setDouble(const char* name, double value) throw (IllegalArgumentException) ; + virtual float getFloat(const char* name) throw (MessageFormatException) ; + virtual void setFloat(const char* name, float value) throw (IllegalArgumentException) ; + virtual int getInt(const char* name) throw (MessageFormatException) ; + virtual void setInt(const char* name, int value) throw (IllegalArgumentException) ; + virtual long long getLong(const char* name) throw (MessageFormatException) ; + virtual void setLong(const char* name, long long value) throw (IllegalArgumentException) ; + virtual short getShort(const char* name) throw (MessageFormatException) ; + virtual void setShort(const char* name, short value) throw (IllegalArgumentException) ; + virtual p getString(const char* name) throw (MessageFormatException) ; + virtual void setString(const char* name, p value) throw (IllegalArgumentException) ; + virtual ap getMapNames() ; + virtual bool itemExists(const char* name) ; +} ; + +/* namespace */ + } + } + } +} + +#endif /*ActiveMQMapMessage_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/command/ActiveMQTempQueue.cpp b/openwire-cpp/src/command/ActiveMQTempQueue.cpp new file mode 100644 index 0000000000..48f18c1743 --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQTempQueue.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 "command/ActiveMQTempQueue.hpp" + +using namespace apache::activemq::client::command; + +/* + * + */ +ActiveMQTempQueue::ActiveMQTempQueue() + : ActiveMQDestination() +{ +} + +ActiveMQTempQueue::ActiveMQTempQueue(const char* name) + : ActiveMQDestination(name) +{ +} + +ActiveMQTempQueue::~ActiveMQTempQueue() +{ +} + +p ActiveMQTempQueue::getQueueName() +{ + return this->getPhysicalName() ; +} + +int ActiveMQTempQueue::getDestinationType() +{ + return ActiveMQDestination::ACTIVEMQ_QUEUE ; +} + +p ActiveMQTempQueue::createDestination(const char* name) +{ + p tempQueue = new ActiveMQTempQueue(name) ; + return tempQueue ; +} diff --git a/openwire-cpp/src/command/ActiveMQTempQueue.hpp b/openwire-cpp/src/command/ActiveMQTempQueue.hpp new file mode 100644 index 0000000000..af62c303a8 --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQTempQueue.hpp @@ -0,0 +1,56 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 ActiveMQTempQueue_hpp_ +#define ActiveMQTempQueue_hpp_ + +#include "ITemporaryQueue.hpp" +#include "command/ActiveMQDestination.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + namespace command + { + +/* + * + */ +class ActiveMQTempQueue : public ActiveMQDestination, ITemporaryQueue +{ +public: + const static char TYPE = 102 ; + +public: + ActiveMQTempQueue() ; + ActiveMQTempQueue(const char* name) ; + virtual ~ActiveMQTempQueue() ; + + virtual p getQueueName() ; + virtual int getDestinationType() ; + virtual p createDestination(const char* name) ; +} ; + +/* namespace */ + } + } + } +} + +#endif /*ActiveMQTempQueue_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/command/ActiveMQTempTopic.cpp b/openwire-cpp/src/command/ActiveMQTempTopic.cpp new file mode 100644 index 0000000000..42368ef2a5 --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQTempTopic.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 "command/ActiveMQTempTopic.hpp" + +using namespace apache::activemq::client::command; + +/* + * + */ +ActiveMQTempTopic::ActiveMQTempTopic() + : ActiveMQDestination() +{ +} + +ActiveMQTempTopic::ActiveMQTempTopic(const char* name) + : ActiveMQDestination(name) +{ +} + +ActiveMQTempTopic::~ActiveMQTempTopic() +{ +} + +p ActiveMQTempTopic::getTopicName() +{ + return this->getPhysicalName() ; +} + +int ActiveMQTempTopic::getDestinationType() +{ + return ActiveMQDestination::ACTIVEMQ_QUEUE ; +} + +p ActiveMQTempTopic::createDestination(const char* name) +{ + p tempTopic = new ActiveMQTempTopic(name) ; + return tempTopic ; +} diff --git a/openwire-cpp/src/command/ActiveMQTempTopic.hpp b/openwire-cpp/src/command/ActiveMQTempTopic.hpp new file mode 100644 index 0000000000..ff1d8ab0cc --- /dev/null +++ b/openwire-cpp/src/command/ActiveMQTempTopic.hpp @@ -0,0 +1,56 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 ActiveMQTempTopic_hpp_ +#define ActiveMQTempTopic_hpp_ + +#include "ITemporaryTopic.hpp" +#include "command/ActiveMQDestination.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + namespace command + { + +/* + * + */ +class ActiveMQTempTopic : public ActiveMQDestination, ITemporaryTopic +{ +public: + const static char TYPE = 103 ; + +public: + ActiveMQTempTopic() ; + ActiveMQTempTopic(const char* name) ; + virtual ~ActiveMQTempTopic() ; + + virtual p getTopicName() ; + virtual int getDestinationType() ; + virtual p createDestination(const char* name) ; +} ; + +/* namespace */ + } + } + } +} + +#endif /*ActiveMQTempTopic_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/util/ConversionException.hpp b/openwire-cpp/src/util/ConversionException.hpp new file mode 100644 index 0000000000..73d22339f5 --- /dev/null +++ b/openwire-cpp/src/util/ConversionException.hpp @@ -0,0 +1,52 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 ConversionException_hpp_ +#define ConversionException_hpp_ + +#include "TraceException.hpp" + +namespace apache +{ + namespace activemq + { + namespace client + { + namespace util + { + using namespace std ; + +/* + * Signals that an illegal data conversion has occurred. + */ +class ConversionException : public TraceException +{ +public: + ConversionException() : TraceException() + { /* no-op */ } ; + ConversionException(const char *const& msg) : TraceException(msg) + { /* no-op */ } ; + ConversionException(const char* fileName, int lineNo, const char* msg) : TraceException(msg) + { /* no-op */ } ; +} ; + +/* namespace */ + } + } + } +} + +#endif /*ConversionException_hpp_*/ \ No newline at end of file diff --git a/openwire-cpp/src/util/MapItemHolder.cpp b/openwire-cpp/src/util/MapItemHolder.cpp new file mode 100644 index 0000000000..647fc0da7f --- /dev/null +++ b/openwire-cpp/src/util/MapItemHolder.cpp @@ -0,0 +1,201 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 "util/MapItemHolder.hpp" + +using namespace apache::activemq::client::util; + +/* + * + */ +MapItemHolder::MapItemHolder(bool value) +{ + this->value = new bool(value) ; + this->type = MapItemHolder::BOOLEAN ; +} + +MapItemHolder::MapItemHolder(char value) +{ + this->value = new char(value) ; + this->type = MapItemHolder::BYTE ; +} + +MapItemHolder::MapItemHolder(ap value) +{ + this->value = ap_help::get_obj (value); + addref(value) ; + this->type = MapItemHolder::BYTEARRAY ; +} + +MapItemHolder::MapItemHolder(double value) +{ + this->value = new double(value) ; + this->type = MapItemHolder::DOUBLE ; +} + +MapItemHolder::MapItemHolder(float value) +{ + this->value = new float(value) ; + this->type = MapItemHolder::FLOAT ; +} + +MapItemHolder::MapItemHolder(int value) +{ + this->value = new int(value) ; + this->type = MapItemHolder::INTEGER ; +} + +MapItemHolder::MapItemHolder(long long value) +{ + this->value = new long long(value) ; + this->type = MapItemHolder::LONG ; +} + +MapItemHolder::MapItemHolder(short value) +{ + this->value = new short(value) ; + this->type = MapItemHolder::SHORT ; +} + +MapItemHolder::MapItemHolder(p value) +{ + this->value = p_help::get_obj (value); + addref(value) ; + this->type = MapItemHolder::STRING ; +} + + +MapItemHolder::~MapItemHolder() +{ + if( type == BYTEARRAY ) + release (reinterpret_cast (value)); + else if( type == STRING ) + reinterpret_cast*> (value)->release(); + else + delete value ; +} + +bool MapItemHolder::getBoolean() throw (ConversionException) +{ + if( type == BOOLEAN ) + return *(reinterpret_cast (value)) ; + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a boolean") ; +} + +char MapItemHolder::getByte() throw (ConversionException) +{ + if( type == BYTE ) + return *(reinterpret_cast (value)) ; + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a byte") ; +} + +ap MapItemHolder::getBytes() throw (ConversionException) +{ + if( type == BYTEARRAY ) { + ap retval; + ap_help::set_obj (retval, value); + addref (retval); + return retval; + } + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a byte array") ; +} + +double MapItemHolder::getDouble() throw (ConversionException) +{ + if( type == DOUBLE || type == FLOAT ) + return *(reinterpret_cast (value)) ; + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a double") ; +} + +float MapItemHolder::getFloat() throw (ConversionException) +{ + if( type == FLOAT ) + return *(reinterpret_cast (value)) ; + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a float") ; +} + +int MapItemHolder::getInt() throw (ConversionException) +{ + if( type == INTEGER || type == SHORT || type == LONG ) + return *(reinterpret_cast (value)) ; + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to an integer") ; +} + +long long MapItemHolder::getLong() throw (ConversionException) +{ + if( type == INTEGER || type == SHORT || type == LONG ) + return *(reinterpret_cast (value)) ; + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a long") ; +} + +short MapItemHolder::getShort() throw (ConversionException) +{ + if( type == INTEGER || type == SHORT || type == LONG ) + return *(reinterpret_cast (value)) ; + else + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a short") ; +} + +p MapItemHolder::getString() throw (ConversionException) +{ + p retval ; + char buffer[25] ; + + switch( type ) + { + case STRING: + p_help::set_obj (retval, value) ; + addref (retval) ; + return retval ; + + case BOOLEAN: + sprintf(buffer, "%s", ( getBoolean() ? "true" : "false" ) ) ; + retval = new string(buffer) ; + return retval ; + + case BYTE: + case SHORT: + case INTEGER: + sprintf(buffer, "%d", getInt() ) ; + retval = new string(buffer) ; + return retval ; + + case LONG: + sprintf(buffer, "%I64d", getLong() ) ; + retval = new string(buffer) ; + return retval ; + + case FLOAT: + sprintf(buffer, "%f", getFloat() ) ; + retval = new string(buffer) ; + return retval ; + + case DOUBLE: + sprintf(buffer, "%lf", getDouble() ) ; + retval = new string(buffer) ; + return retval ; + + default: + throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a string") ; + } +} diff --git a/openwire-cpp/src/util/MapItemHolder.hpp b/openwire-cpp/src/util/MapItemHolder.hpp new file mode 100644 index 0000000000..6412a9bab3 --- /dev/null +++ b/openwire-cpp/src/util/MapItemHolder.hpp @@ -0,0 +1,89 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 MapItemHolder_hpp_ +#define MapItemHolder_hpp_ + +#include +#include "command/ActiveMQDestination.hpp" +#include "util/ConversionException.hpp" +#include "util/ifr/ap" +#include "util/ifr/p" + +// Turn off warning message for ignored exception specification +#ifdef _MSC_VER +#pragma warning( disable : 4290 ) +#endif + +namespace apache +{ + namespace activemq + { + namespace client + { + namespace util + { + using namespace ifr; + +/* + * + */ +class MapItemHolder +{ +private: + void* value ; + int type ; + + const static int BOOLEAN = 0x00 ; + const static int BYTE = 0x01 ; + const static int BYTEARRAY = 0x02 ; + const static int DOUBLE = 0x03 ; + const static int FLOAT = 0x04 ; + const static int INTEGER = 0x05 ; + const static int LONG = 0x06 ; + const static int SHORT = 0x07 ; + const static int STRING = 0x08 ; + +public: + MapItemHolder(bool value) ; + MapItemHolder(char value) ; + MapItemHolder(ap value) ; + MapItemHolder(double value) ; + MapItemHolder(float value) ; + MapItemHolder(int value) ; + MapItemHolder(long long value) ; + MapItemHolder(short value) ; + MapItemHolder(p value) ; + ~MapItemHolder() ; + + bool getBoolean() throw (ConversionException) ; + char getByte() throw (ConversionException) ; + ap getBytes() throw (ConversionException) ; + double getDouble() throw (ConversionException) ; + float getFloat() throw (ConversionException) ; + int getInt() throw (ConversionException) ; + long long getLong() throw (ConversionException) ; + short getShort() throw (ConversionException) ; + p getString() throw (ConversionException) ; +} ; + +/* namespace */ + } + } + } +} + +#endif /*MapItemHolder_hpp_*/ \ No newline at end of file