You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2008/04/29 22:52:37 UTC
svn commit: r652104 [13/29] - in /activemq/activemq-cpp/trunk: ./ m4/
src/examples/ src/examples/consumers/ src/main/ src/main/decaf/
src/main/decaf/internal/ src/main/decaf/internal/net/
src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/m...
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,156 @@
+/*
+ * 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 _DECAF_NET_SOCKETOUTPUTSTREAM_H_
+#define _DECAF_NET_SOCKETOUTPUTSTREAM_H_
+
+#include <decaf/io/OutputStream.h>
+#include <decaf/net/Socket.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+namespace decaf{
+namespace net{
+
+ /**
+ * Output stream for performing write operations
+ * on a socket.
+ */
+ class DECAF_API SocketOutputStream : public io::OutputStream {
+ private:
+
+ // The socket.
+ Socket::SocketHandle socket;
+ util::concurrent::Mutex mutex;
+ bool closed;
+
+ public:
+
+ /**
+ * Constructor.
+ * @param socket the socket handle.
+ */
+ SocketOutputStream( Socket::SocketHandle socket );
+
+ virtual ~SocketOutputStream();
+
+ /**
+ * Writes a single byte to the output stream.
+ * @param c the byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( unsigned char c ) throw ( io::IOException );
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The bytes to write.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const std::vector<unsigned char>& buffer )
+ throw ( io::IOException );
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param offset, the position to start writing in buffer.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ * @throws NullPointerException thrown if buffer is Null.
+ */
+ virtual void write( const unsigned char* buffer,
+ std::size_t offset,
+ std::size_t len )
+ throw ( io::IOException, lang::exceptions::NullPointerException );
+
+ /**
+ * Flush - does nothing.
+ * @throws IOException
+ */
+ virtual void flush() throw ( io::IOException ){};
+
+ /**
+ * Close - does nothing. It is the responsibility of the owner
+ * of the socket object to close it.
+ * @throws CMSException
+ */
+ virtual void close() throw( lang::Exception );
+
+ public:
+
+ /**
+ * Locks the object.
+ * @throws Exception
+ */
+ virtual void lock() throw( lang::Exception ){
+ mutex.lock();
+ }
+
+ /**
+ * Unlocks the object.
+ * @throws Exception
+ */
+ virtual void unlock() throw( lang::Exception ){
+ mutex.unlock();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling.
+ * @throws Exception
+ */
+ virtual void wait() throw( lang::Exception ){
+ mutex.wait();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling. This wait will timeout after the specified time
+ * interval.
+ * @param millisecs time in millisecsonds to wait, or WAIT_INIFINITE
+ * @throws Exception
+ */
+ virtual void wait( unsigned long millisecs )
+ throw( lang::Exception ) {
+
+ mutex.wait( millisecs );
+ }
+
+ /**
+ * Signals a waiter on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ * @throws Exception
+ */
+ virtual void notify() throw( lang::Exception ){
+ mutex.notify();
+ }
+
+ /**
+ * Signals the waiters on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ */
+ virtual void notifyAll() throw( lang::Exception ){
+ mutex.notifyAll();
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_SOCKETOUTPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketTimeoutException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketTimeoutException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketTimeoutException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketTimeoutException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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 _DECAF_NET_SOCKETTIMEOUTEXCEPTION_H_
+#define _DECAF_NET_SOCKETTIMEOUTEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/InterruptedIOException.h>
+
+namespace decaf{
+namespace net{
+
+ class DECAF_API SocketTimeoutException : public io::InterruptedIOException {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ SocketTimeoutException() throw() {}
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ SocketTimeoutException( const Exception& ex ) throw()
+ : io::InterruptedIOException()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ SocketTimeoutException( const SocketTimeoutException& ex ) throw()
+ : io::InterruptedIOException()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. 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 message to report
+ * @param list of primitives that are formatted into the message
+ */
+ SocketTimeoutException( const char* file, const int lineNumber,
+ const char* msg, ... ) throw ()
+ : io::InterruptedIOException()
+ {
+ 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 SocketTimeoutException* clone() const {
+ return new SocketTimeoutException( *this );
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~SocketTimeoutException() throw() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_SOCKETTIMEOUTEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,335 @@
+/*
+ * 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 <decaf/util/Config.h>
+
+#include "TcpSocket.h"
+#include "SocketInputStream.h"
+#include "SocketOutputStream.h"
+#include "SocketError.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::net;
+using namespace decaf::io;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+TcpSocket::TcpSocket() throw ( SocketException )
+ : socketHandle( INVALID_SOCKET_HANDLE ),
+ inputStream( NULL ),
+ outputStream( NULL ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+TcpSocket::TcpSocket( SocketHandle socketHandle )
+ : socketHandle( INVALID_SOCKET_HANDLE ),
+ inputStream( NULL ),
+ outputStream( NULL ) {
+
+ try {
+ this->socketHandle = socketHandle;
+ this->inputStream = new SocketInputStream( socketHandle );
+ this->outputStream = new SocketOutputStream( socketHandle );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+TcpSocket::~TcpSocket() {
+
+ try{
+
+ // No shutdown, just close - dont want blocking destructor.
+ close();
+
+ // Destroy the input stream.
+ if( inputStream != NULL ){
+ delete inputStream;
+ inputStream = NULL;
+ }
+
+ // Destroy the output stream.
+ if( outputStream != NULL ){
+ delete outputStream;
+ outputStream = NULL;
+ }
+ }
+ DECAF_CATCH_NOTHROW( Exception )
+ DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InputStream* TcpSocket::getInputStream(){
+ return inputStream;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OutputStream* TcpSocket::getOutputStream(){
+ return outputStream;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::connect(const char* host, int port, int timeout) throw ( SocketException ) {
+
+ try{
+
+ if( isConnected() ) {
+ throw SocketException( __FILE__, __LINE__,
+ "Socket::connect - Socket already connected. host: %s, port: %d", host, port );
+ }
+
+ // Create the Address data
+ checkResult( apr_sockaddr_info_get(
+ &socketAddress, host, APR_INET, port, 0, apr_pool.getAprPool() ) );
+
+ // Create the actual socket.
+ checkResult( apr_socket_create(
+ &socketHandle, socketAddress->family, SOCK_STREAM, APR_PROTO_TCP, apr_pool.getAprPool() ) );
+
+ // To make blocking-with-timeout sockets, we have to set it to
+ // 'APR_SO_NONBLOCK==1(on) and timeout>0'. On Unix, we have no
+ // problem to specify 'APR_SO_NONBLOCK==0(off) and timeout>0'.
+ // Unfortunatelly, we have a problem on Windows. Setting the
+ // mode to 'APR_SO_NONBLOCK==0(off) and timeout>0' causes
+ // blocking-with-system-timeout sockets on Windows.
+ //
+ // http://dev.ariel-networks.com/apr/apr-tutorial/html/apr-tutorial-13.html
+
+ // If we have a connection timeout specified, temporarily set the socket to
+ // non-blocking so that we can timeout the connect operation. We'll restore
+ // to blocking mode right after we connect.
+ apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, (timeout>0)?1:0 );
+ apr_socket_timeout_set( socketHandle, timeout );
+
+ // Connect to the broker.
+ checkResult(apr_socket_connect( socketHandle, socketAddress ));
+
+ // Now that we are connected, we want to go back to blocking.
+ apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, 0 );
+ apr_socket_timeout_set( socketHandle, -1 );
+
+ // Create an input/output stream for this socket.
+ inputStream = new SocketInputStream( socketHandle );
+ outputStream = new SocketOutputStream( socketHandle );
+
+ } catch( SocketException& ex ) {
+ ex.setMark( __FILE__, __LINE__);
+ try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
+ throw ex;
+ } catch( ... ) {
+ try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
+ throw SocketException(
+ __FILE__, __LINE__,
+ "TcpSocket::connect() - caught unknown exception" );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::close() throw( lang::Exception ) {
+
+ try{
+ // Destroy the input stream.
+ if( inputStream != NULL ){
+ inputStream->close();
+ }
+
+ // Destroy the output stream.
+ if( outputStream != NULL ){
+ outputStream->close();
+ }
+
+ // When connected we first shutdown, which breaks our reads and writes
+ // then we close to free APR resources.
+ if( isConnected() ) {
+ apr_socket_shutdown( socketHandle, APR_SHUTDOWN_READWRITE );
+ apr_socket_close( socketHandle );
+ socketHandle = INVALID_SOCKET_HANDLE;
+ }
+ }
+ DECAF_CATCH_RETHROW( lang::Exception )
+ DECAF_CATCHALL_THROW( lang::Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int TcpSocket::getSoLinger() const throw( SocketException ){
+
+ try{
+ int value = 0;
+ checkResult( apr_socket_opt_get( socketHandle, APR_SO_LINGER, &value ) );
+ return value;
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::setSoLinger( int dolinger ) throw( SocketException ){
+
+ try{
+ checkResult( apr_socket_opt_set( socketHandle, APR_SO_LINGER, dolinger ) );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool TcpSocket::getKeepAlive() const throw( SocketException ){
+
+ try{
+ int value = 0;
+ checkResult( apr_socket_opt_get( socketHandle, APR_SO_KEEPALIVE, &value ) );
+ return value != 0;
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::setKeepAlive( const bool keepAlive ) throw( SocketException ){
+
+ try{
+ int value = keepAlive ? 1 : 0;
+ checkResult( apr_socket_opt_set( socketHandle, APR_SO_KEEPALIVE, value ) );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int TcpSocket::getReceiveBufferSize() const throw( SocketException ){
+
+ try{
+ int value;
+ checkResult( apr_socket_opt_get( socketHandle, APR_SO_RCVBUF, &value ) );
+ return value;
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::setReceiveBufferSize( int size ) throw( SocketException ){
+
+ try{
+ checkResult( apr_socket_opt_set( socketHandle, APR_SO_RCVBUF, size ) );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool TcpSocket::getReuseAddress() const throw( SocketException ){
+
+ try{
+ int value;
+ checkResult( apr_socket_opt_get( socketHandle, APR_SO_REUSEADDR, &value ) );
+ return value != 0;
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::setReuseAddress( bool reuse ) throw( SocketException ){
+
+ try{
+ int value = reuse ? 1 : 0;
+ checkResult( apr_socket_opt_set( socketHandle, APR_SO_REUSEADDR, value ) );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int TcpSocket::getSendBufferSize() const throw( SocketException ){
+
+ try{
+ int value;
+ checkResult( apr_socket_opt_get( socketHandle, APR_SO_SNDBUF, &value ) );
+ return value;
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::setSendBufferSize( int size ) throw( SocketException ){
+
+ try{
+ checkResult( apr_socket_opt_set( socketHandle, APR_SO_SNDBUF, size ) );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::setSoTimeout ( const int millisecs ) throw ( SocketException ) {
+
+ try{
+ // Time is in microseconds so multiply by 1000.
+ checkResult( apr_socket_timeout_set( socketHandle, millisecs * 1000 ) );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int TcpSocket::getSoTimeout() const throw( SocketException ) {
+
+ try{
+ // Time is in microseconds so divide by 1000.
+ apr_interval_time_t value = 0;
+ checkResult( apr_socket_timeout_get( socketHandle, &value ) );
+ return (int)( value / 1000 );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool TcpSocket::getTcpNoDelay() const throw ( lang::Exception ) {
+
+ try{
+ int value;
+ checkResult( apr_socket_opt_get( socketHandle, APR_TCP_NODELAY, &value ) );
+ return value != 0;
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::setTcpNoDelay( bool value ) throw ( lang::Exception ) {
+
+ try{
+ int ivalue = value ? 1 : 0;
+ checkResult( apr_socket_opt_set( socketHandle, APR_TCP_NODELAY, ivalue ) );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::checkResult( apr_status_t value ) const throw ( SocketException ) {
+
+ if( value != APR_SUCCESS ){
+ throw SocketException(
+ __FILE__, __LINE__,
+ SocketError::getErrorString().c_str() );
+ }
+}
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/TcpSocket.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,252 @@
+/*
+ * 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 _DECAF_NET_TCPSOCKET_H_
+#define _DECAF_NET_TCPSOCKET_H_
+
+#include <decaf/net/SocketException.h>
+#include <decaf/net/Socket.h>
+#include <decaf/io/InputStream.h>
+#include <decaf/io/OutputStream.h>
+#include <decaf/util/Config.h>
+#include <decaf/internal/AprPool.h>
+
+namespace decaf{
+namespace net{
+
+ // Forward declarations
+ class SocketInputStream;
+ class SocketOutputStream;
+
+ /**
+ * Platform-independent implementation of the socket interface.
+ */
+ class DECAF_API TcpSocket : public Socket {
+ private:
+
+ /**
+ * APR Socket Pool to allocate from
+ */
+ decaf::internal::AprPool apr_pool;
+
+ /**
+ * The handle for this socket.
+ */
+ SocketHandle socketHandle;
+
+ /**
+ * The Address info for this Socket
+ */
+ SocketAddress socketAddress;
+
+ /**
+ * The input stream for reading this socket.
+ */
+ SocketInputStream* inputStream;
+
+ /**
+ * The output stream for writing to this socket.
+ */
+ SocketOutputStream* outputStream;
+
+ public:
+
+ /**
+ * Construct a non-connected socket.
+ * @throws SocketException thrown one windows if the static initialization
+ * call to WSAStartup was not successful.
+ */
+ TcpSocket() throw ( SocketException );
+
+ /**
+ * Construct a connected or bound socket based on given
+ * socket handle.
+ * @param socketHandle a socket handle to wrap in the object
+ */
+ TcpSocket( SocketHandle socketHandle );
+
+ /**
+ * Destruct.
+ * Releases the socket handle but not
+ * gracefully shut down the connection.
+ */
+ virtual ~TcpSocket();
+
+ /**
+ * Gets the handle for the socket.
+ * @return SocketHabler for this Socket, can be NULL
+ */
+ SocketHandle getSocketHandle () {
+ return socketHandle;
+ }
+
+ /**
+ * Connects to the specified destination. Closes this socket if
+ * connected to another destination.
+ * @param host The host of the server to connect to.
+ * @param port The port of the server to connect to.
+ * @param timeout of socket in microseconds
+ * @throws IOException Thrown if a failure occurred in the connect.
+ */
+ void connect( const char* host, int port, int timeout) throw( SocketException );
+
+ /**
+ * Connects to the specified destination. Closes this socket if
+ * connected to another destination.
+ * @param host The host of the server to connect to.
+ * @param port The port of the server to connect to.
+ * @throws IOException Thrown if a failure occurred in the connect.
+ */
+ virtual void connect( const char* host, int port ) throw(SocketException)
+ {
+ connect(host,port,-1);
+ }
+
+ /**
+ * Indicates whether or not this socket is connected to a destination.
+ * @return true if connected
+ */
+ virtual bool isConnected() const{
+ return socketHandle != INVALID_SOCKET_HANDLE;
+ }
+
+ /**
+ * Gets the InputStream for this socket.
+ * @return The InputStream for this socket. NULL if not connected.
+ */
+ virtual io::InputStream* getInputStream();
+
+ /**
+ * Gets the OutputStream for this socket.
+ * @return the OutputStream for this socket. NULL if not connected.
+ */
+ virtual io::OutputStream* getOutputStream();
+
+ /**
+ * Gets the linger time.
+ * @return The linger time in seconds.
+ * @throws SocketException if the operation fails.
+ */
+ virtual int getSoLinger() const throw( SocketException );
+
+ /**
+ * Sets the linger time.
+ * @param linger The linger time in seconds. If 0, linger is off.
+ * @throws SocketException if the operation fails.
+ */
+ virtual void setSoLinger( int linger ) throw( SocketException );
+
+ /**
+ * Gets the keep alive flag.
+ * @return True if keep alive is enabled.
+ * @throws SocketException if the operation fails.
+ */
+ virtual bool getKeepAlive() const throw( SocketException );
+
+ /**
+ * Enables/disables the keep alive flag.
+ * @param keepAlive If true, enables the flag.
+ * @throws SocketException if the operation fails.
+ */
+ virtual void setKeepAlive( bool keepAlive ) throw( SocketException );
+
+ /**
+ * Gets the receive buffer size.
+ * @return the receive buffer size in bytes.
+ * @throws SocketException if the operation fails.
+ */
+ virtual int getReceiveBufferSize() const throw( SocketException );
+
+ /**
+ * Sets the recieve buffer size.
+ * @param size Number of bytes to set the receive buffer to.
+ * @throws SocketException if the operation fails.
+ */
+ virtual void setReceiveBufferSize( int size ) throw( SocketException );
+
+ /**
+ * Gets the reuse address flag.
+ * @return True if the address can be reused.
+ * @throws SocketException if the operation fails.
+ */
+ virtual bool getReuseAddress() const throw( SocketException );
+
+ /**
+ * Sets the reuse address flag.
+ * @param reuse If true, sets the flag.
+ * @throws SocketException if the operation fails.
+ */
+ virtual void setReuseAddress( bool reuse ) throw( SocketException );
+
+ /**
+ * Gets the send buffer size.
+ * @return the size in bytes of the send buffer.
+ * @throws SocketException if the operation fails.
+ */
+ virtual int getSendBufferSize() const throw( SocketException );
+
+ /**
+ * Sets the send buffer size.
+ * @param size The number of bytes to set the send buffer to.
+ * @throws SocketException if the operation fails.
+ */
+ virtual void setSendBufferSize( int size ) throw( SocketException );
+
+ /**
+ * Gets the timeout for socket operations.
+ * @return The timeout in milliseconds for socket operations.
+ * @throws SocketException Thrown if unable to retrieve the information.
+ */
+ virtual int getSoTimeout() const throw( SocketException );
+
+ /**
+ * Sets the timeout for socket operations.
+ * @param timeout The timeout in milliseconds for socket operations.<p>
+ * @throws SocketException Thrown if unable to set the information.
+ */
+ virtual void setSoTimeout( int timeout ) throw(SocketException);
+
+ /**
+ * Closes this object and deallocates the appropriate resources.
+ * @throws CMSException
+ */
+ virtual void close() throw( lang::Exception );
+
+ public:
+
+ /**
+ * Gets the Status of the TCP_NODELAY param for this socket as a Bool
+ * @returns true if TCP_NODELAY is enabled
+ * @throws CMSException
+ */
+ virtual bool getTcpNoDelay() const throw ( lang::Exception );
+
+ /**
+ * Sets the Status of the TCP_NODELAY param for this socket as a Bool
+ * @param value - true if TCP_NODELAY is to be enabled
+ * @throws CMSException
+ */
+ virtual void setTcpNoDelay( bool value ) throw ( lang::Exception );
+
+ protected:
+
+ void checkResult( apr_status_t value ) const throw (SocketException);
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_TCPSOCKET_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URI.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URI.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URI.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URI.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,286 @@
+/*
+ * 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 "URI.h"
+
+#include <apr_strings.h>
+#include <decaf/lang/Integer.h>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+const std::string URI::unreserved = "_-!.~\'()*";
+const std::string URI::punct = ",;:$&+=";
+const std::string URI::reserved = punct + "?/[]@";
+const std::string URI::someLegal = unreserved + punct;
+const std::string URI::allLegal = unreserved + reserved;
+
+////////////////////////////////////////////////////////////////////////////////
+URI::URI( const std::string& uri ) throw ( URISyntaxException) {
+
+ this->uriString = NULL;
+ this->parseURI( uri );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URI::URI( const std::string& scheme,
+ const std::string& ssp,
+ const std::string& fragment ) throw ( URISyntaxException ) {
+
+ std::string uri = "";
+
+ if( scheme != "" ) {
+ uri.append( scheme );
+ uri.append( ":" );
+ }
+
+ if( ssp != "" ) {
+ // QUOTE ILLEGAL CHARACTERS
+ uri.append( quoteComponent( ssp, allLegal ) );
+ }
+
+ if( fragment != "" ) {
+ uri.append( "#" );
+ // QUOTE ILLEGAL CHARACTERS
+ uri.append( quoteComponent( fragment, allLegal ) );
+ }
+
+ // Now hand of to the main parse function.
+ this->parseURI( uri );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URI::URI( const std::string& scheme, const std::string& userInfo,
+ const std::string& host, int port,
+ const std::string& path, const std::string& query,
+ const std::string& fragment ) throw ( URISyntaxException ) {
+
+ this->uriString = NULL;
+
+ if( scheme == "" && userInfo == "" && host == "" &&
+ path == "" && query == "" && fragment == "" ) {
+
+ this->uri.path = "";
+ return;
+ }
+
+ if( scheme != "" && path.length() > 0 && path.at(0) != '/') {
+
+ throw URISyntaxException(
+ __FILE__, __LINE__, path,
+ "URI::URI - Path string: %s starts with invalid char '/'" );
+ }
+
+ std::string uri = "";
+ if( scheme != "" ) {
+ uri.append( scheme );
+ uri.append( ":" );
+ }
+
+ if( userInfo != "" || host != "" || port != -1 ) {
+ uri.append( "//" );
+ }
+
+ if( userInfo != "" ) {
+ // QUOTE ILLEGAL CHARACTERS in userinfo
+ uri.append(quoteComponent( userInfo, someLegal ) );
+ uri.append( "@" );
+ }
+
+ if( host != "" ) {
+ std::string newHost = host;
+
+ // check for ipv6 addresses that hasn't been enclosed
+ // in square brackets
+ if( host.find( ":" ) != std::string::npos &&
+ host.find( "]" ) == std::string::npos &&
+ host.find( "[" ) == std::string::npos ) {
+
+ newHost = std::string( "[" ) + host + "]";
+ }
+
+ uri.append( newHost );
+ }
+
+ if( port != -1 ) {
+ uri.append( ":" );
+ uri.append( Integer::toString( port ) );
+ }
+
+ if( path != "" ) {
+ // QUOTE ILLEGAL CHARS
+ uri.append( quoteComponent( path, "/@" + someLegal ) );
+ }
+
+ if( query != "" ) {
+ uri.append( "?" );
+ // QUOTE ILLEGAL CHARS
+ uri.append( quoteComponent( query, allLegal ) );
+ }
+
+ if( fragment != "" ) {
+ // QUOTE ILLEGAL CHARS
+ uri.append( "#" );
+ uri.append( quoteComponent( fragment, allLegal ) );
+ }
+
+ this->parseURI( uri );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URI::URI( const std::string& scheme, const std::string& host,
+ const std::string& path, const std::string& fragment )
+ throw ( URISyntaxException ) {
+
+ this->uriString = NULL;
+
+ URI::URI( scheme, "", host, -1, path, "", fragment );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URI::URI( const std::string& scheme, const std::string& authority,
+ const std::string& path, const std::string& query,
+ const std::string& fragment ) throw ( URISyntaxException ) {
+
+ this->uriString = NULL;
+
+ if( scheme != "" && path.length() > 0 && path.at(0) != '/' ) {
+ throw URISyntaxException(
+ __FILE__, __LINE__, path,
+ "URI::URI - Path String %s must start with a '/'" );
+ }
+
+ std::string uri = "";
+ if( scheme != "" ) {
+ uri.append( scheme );
+ uri.append( ":" );
+ }
+ if( authority != "" ) {
+ uri.append("//");
+ // QUOTE ILLEGAL CHARS
+ uri.append( quoteComponent( authority, "@[]" + someLegal ) );
+ }
+
+ if( path != "" ) {
+ // QUOTE ILLEGAL CHARS
+ uri.append( quoteComponent( path, "/@" + someLegal ) );
+ }
+ if( query != "" ) {
+ // QUOTE ILLEGAL CHARS
+ uri.append( "?" );
+ uri.append( quoteComponent( query, allLegal ) );
+ }
+ if( fragment != "" ) {
+ // QUOTE ILLEGAL CHARS
+ uri.append( "#" );
+ uri.append( quoteComponent( fragment, allLegal ) );
+ }
+
+ this->parseURI( uri );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URI::parseURI( const std::string& uri ) throw ( URISyntaxException ) {
+
+ // Use APR to perform the main parse.
+ apr_status_t result = apr_uri_parse( pool.getAprPool(),
+ uri.c_str(), &this->uri );
+
+ if( result != APR_SUCCESS ) {
+ throw URISyntaxException(
+ __FILE__, __LINE__, uri,
+ "URI::praseURI - URI String %s invalid." );
+ }
+
+ std::cout << "\n";
+ std::cout << "Original URI String: " << uri << std::endl;
+ std::cout << "\n";
+ std::cout << "Scheme: "
+ << ( this->uri.scheme ? this->uri.scheme : "" ) << std::endl;
+ std::cout << "Host: "
+ << ( this->uri.hostinfo ? this->uri.hostinfo : "" ) << std::endl;
+ std::cout << "User: "
+ << ( this->uri.user ? this->uri.user : "" ) << std::endl;
+ std::cout << "Passwrod: "
+ << ( this->uri.password ? this->uri.password : "" ) << std::endl;
+ std::cout << "Host Name: "
+ << ( this->uri.hostname ? this->uri.hostname : "" ) << std::endl;
+ std::cout << "Port Str: "
+ << ( this->uri.port_str ? this->uri.port_str : "" ) << std::endl;
+ std::cout << "Path: "
+ << ( this->uri.path ? this->uri.path : "" ) << std::endl;
+ std::cout << "Query: "
+ << ( this->uri.query ? this->uri.query : "" ) << std::endl;
+ std::cout << "Fragment: "
+ << ( this->uri.fragment ? this->uri.fragment : "" ) << std::endl;
+ std::cout << "Port: " << this->uri.port << std::endl;
+ std::cout << "Is Initialized: " << this->uri.is_initialized << std::endl;
+ std::cout << "DNS Looked Up: " << this->uri.dns_looked_up << std::endl;
+ std::cout << "DNS Resolved: " << this->uri.dns_resolved << std::endl;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int URI::compareTo( DECAF_UNUSED const URI& value ) const {
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool URI::equals( const URI& value ) const {
+ return compareTo( value ) == 0 ? true : false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool URI::operator==( const URI& value ) const {
+ return compareTo( value ) == 0 ? true : false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool URI::operator<( const URI& value ) const {
+ return compareTo( value ) == -1 ? true : false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URI URI::create( const std::string uri )
+ throw ( lang::exceptions::IllegalArgumentException ) {
+
+ try {
+ return URI( uri );
+ } catch( URISyntaxException& e ) {
+ throw IllegalArgumentException( e );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URI::quoteComponent( DECAF_UNUSED const std::string& component,
+ DECAF_UNUSED const std::string& legalset ) {
+// try {
+ /*
+ * Use a different encoder than URLEncoder since: 1. chars like "/",
+ * "#", "@" etc needs to be preserved instead of being encoded, 2.
+ * UTF-8 char set needs to be used for encoding instead of default
+ * platform one
+ */
+// return URIEncoderDecoder.quoteIllegal(component, legalset);
+// } catch( UnsupportedEncodingException e ) {
+// throw RuntimeException( e );
+// }
+
+ return "";
+}
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URI.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URI.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URI.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URI.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,433 @@
+/*
+ * 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 _DECAF_NET_URI_H_
+#define _DECAF_NET_URI_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/lang/Comparable.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+#include <decaf/net/URISyntaxException.h>
+#include <decaf/net/MalformedURLException.h>
+#include <decaf/net/URL.h>
+#include <string>
+#include <apr_uri.h>
+#include <decaf/internal/AprPool.h>
+
+namespace decaf{
+namespace net{
+
+ /**
+ * This class represents an instance of a URI as defined by RFC 2396.
+ */
+ class DECAF_API URI : public lang::Comparable<URI> {
+ private:
+
+ // Apr Data for parsing the uri.
+ apr_uri_t uri;
+ internal::AprPool pool;
+
+ // The original string entered from URI( string ), empty if not set.
+ const char* uriString;
+
+ static const std::string unreserved;
+ static const std::string punct;
+ static const std::string reserved;
+ static const std::string someLegal;
+ static const std::string allLegal;
+
+ public:
+
+ /**
+ * Constructs a URI from the given string
+ * @param uri - string uri to parse.
+ */
+ URI( const std::string& uri ) throw ( URISyntaxException );
+
+ /**
+ * Constructs a URI from the given components.
+ * @param scheme - the uri scheme
+ * @param ssp - Scheme specific part
+ * @param fragment - Fragment
+ */
+ URI( const std::string& scheme,
+ const std::string& ssp,
+ const std::string& fragment) throw ( URISyntaxException );
+
+ /**
+ * Constructs a URI from the given components.
+ * @param scheme - Scheme name
+ * @param userInfo - User name and authorization information
+ * @param host - Host name
+ * @param port - Port number
+ * @param path - Path
+ * @param query - Query
+ * @param fragment - Fragment
+ */
+ URI( const std::string& scheme, const std::string& userInfo,
+ const std::string& host, int port,
+ const std::string& path, const std::string& query,
+ const std::string& fragment ) throw ( URISyntaxException );
+
+ /**
+ * Constructs a URI from the given components.
+ * @param scheme - Scheme name
+ * @param host - Host name
+ * @param path - Path
+ * @param fragment - Fragment
+ */
+ URI( const std::string& scheme, const std::string& host,
+ const std::string& path, const std::string& fragment )
+ throw ( URISyntaxException );
+
+ /**
+ * Constructs a URI from the given components.
+ * @param scheme - Scheme name
+ * @param authority - Authority
+ * @param path - Path
+ * @param query - Query
+ * @param fragment - Fragment
+ */
+ URI( const std::string& scheme, const std::string& authority,
+ const std::string& path, const std::string& query,
+ const std::string& fragment ) throw ( URISyntaxException);
+
+ virtual ~URI() {}
+
+ /**
+ * Compares this object with the specified object for order. Returns a
+ * negative integer, zero, or a positive integer as this object is less
+ * than, equal to, or greater than the specified object.
+ * @param value - the value to compare to this one.
+ * @returns zero if equal minus one if less than and one if greater than.
+ */
+ virtual int compareTo( const URI& value ) const;
+
+ /**
+ * @return true if this value is considered equal to the passed value.
+ */
+ virtual bool equals( const URI& value ) const;
+
+ /**
+ * Compares equality between this object and the one passed.
+ * @param value - the value to be compared to this one.
+ * @return true if this object is equal to the one passed.
+ */
+ virtual bool operator==( const URI& value ) const;
+
+ /**
+ * Compares this object to another and returns true if this object
+ * is considered to be less than the one passed. This
+ * @param value - the value to be compared to this one.
+ * @return true if this object is equal to the one passed.
+ */
+ virtual bool operator<( const URI& value ) const;
+
+ /**
+ * @eturns the decoded authority component of this URI.
+ */
+ std::string getAuthority() const;
+
+ /**
+ * @returns the decoded fragment component of this URI.
+ */
+ std::string getFragment() const;
+
+ /**
+ * @returns the host component of this URI.
+ */
+ std::string getHost() const;
+
+ /**
+ * @returns the path component of this URI.
+ */
+ std::string getPath() const;
+
+ /**
+ * @returns the port component of this URI.
+ */
+ int getPort() const;
+
+ /**
+ * @returns the query component of this URI.
+ */
+ std::string getQuery() const;
+
+ /**
+ * @returns the scheme component of this URI
+ */
+ std::string getScheme() const;
+
+ /**
+ * @returns the user info component of this URI
+ */
+ std::string getUserInfo() const;
+
+ /**
+ * Returns the raw authority component of this URI.
+ *
+ * The authority component of a URI, if defined, only contains the
+ * commercial-at character ('@') and characters in the unreserved, punct,
+ * escaped, and other categories. If the authority is server-based then
+ * it is further constrained to have valid user-information, host, and
+ * port components.
+ * @returns the raw authority component of the URI
+ */
+ std::string getRawAuthority() const;
+
+ /**
+ * Returns the raw fragment component of this URI.
+ *
+ * The fragment component of a URI, if defined, only contains legal URI
+ * characters.
+ * @returns the raw fragment component of this URI
+ */
+ std::string getRawFragment() const;
+
+ /**
+ * Returns the raw path component of this URI.
+ *
+ * The path component of a URI, if defined, only contains the slash
+ * character ('/'), the commercial-at character ('@'), and characters
+ * in the unreserved, punct, escaped, and other categories.
+ * @returns the raw path component of this URI
+ */
+ std::string getRawPath() const;
+
+ /**
+ * Returns the raw query component of this URI.
+ * The query component of a URI, if defined, only contains legal URI characters.
+ * @returns the raw query component of the URI.
+ */
+ std::string getRawQuery() const;
+
+ /**
+ * Returns the raw scheme-specific part of this URI. The scheme-specific
+ * part is never undefined, though it may be empty.
+ * The scheme-specific part of a URI only contains legal URI characters.
+ * @returns the raw scheme special part of the uri
+ */
+ std::string getRawSchemeSpecificPart() const;
+
+ /**
+ * Returns the decoded scheme-specific part of this URI.
+ * The string returned by this method is equal to that returned by the
+ * getRawSchemeSpecificPart method except that all sequences of escaped
+ * octets are decoded.
+ * @returns the raw scheme specific part of the uri.
+ */
+ std::string getSchemeSpecificPart() const;
+
+ /**
+ * Returns the raw user-information component of this URI.
+ * The user-information component of a URI, if defined, only contains
+ * characters in the unreserved, punct, escaped, and other categories.
+ * @returns the raw user-information component of the URI
+ */
+ std::string getRawUserInfo() const;
+
+ /**
+ * Tells whether or not this URI is absolute. A URI is absolute if,
+ * and only if, it has a scheme component.
+ * @returns true if, and only if, this URI is absolute
+ */
+ bool isAbsolute() const;
+
+ /**
+ * Tells whether or not this URI is opaque. A URI is opaque if, and only
+ * if, it is absolute and its scheme-specific part does not begin with a
+ * slash character ('/'). An opaque URI has a scheme, a scheme-specific
+ * part, and possibly a fragment; all other components are undefined.
+ * @returns true if, and only if, this URI is opaque
+ */
+ bool isOpaque() const;
+
+ /**
+ * Normalizes this URI's path. If this URI is opaque, or if its path is
+ * already in normal form, then this URI is returned. Otherwise a new URI
+ * is constructed that is identical to this URI except that its path is
+ * computed by normalizing this URI's path in a manner consistent with
+ * RFC 2396, section 5.2, step 6, sub-steps c through f; that is:
+ *
+ * 1. All "." segments are removed.
+ * 2. If a ".." segment is preceded by a non-".." segment then both of t
+ * hese segments are removed. This step is repeated until it is no
+ * longer applicable.
+ * 3. If the path is relative, and if its first segment contains a colon
+ * character (':'), then a "." segment is prepended. This prevents a
+ * relative URI with a path such as "a:b/c/d" from later being re-parsed
+ * as an opaque URI with a scheme of "a" and a scheme-specific part of
+ * "b/c/d". (Deviation from RFC 2396)
+ *
+ * A normalized path will begin with one or more ".." segments if there were
+ * insufficient non-".." segments preceding them to allow their removal. A
+ * normalized path will begin with a "." segment if one was inserted by step
+ * 3 above. Otherwise, a normalized path will not contain any "." or ".."
+ * segments.
+ * @returns A URI equivalent to this URI, but whose path is in normal form
+ */
+ URI normalize() const;
+
+ /**
+ * Attempts to parse this URI's authority component, if defined, into
+ * user-information, host, and port components.
+ *
+ * If this URI's authority component has already been recognized as being
+ * server-based then it will already have been parsed into user-information,
+ * host, and port components. In this case, or if this URI has no authority
+ * component, this method simply returns this URI.
+ *
+ * Otherwise this method attempts once more to parse the authority component
+ * into user-information, host, and port components, and throws an exception
+ * describing why the authority component could not be parsed in that way.
+ * @returns A URI whose authority field has been parsed as a server-based
+ * authority
+ * @throws URISyntaxException - If the authority component of this URI is
+ * defined but cannot be parsed as a server-based authority.
+ */
+ URI parseServerAuthority() const throw ( URISyntaxException );
+
+ /**
+ * Relativizes the given URI against this URI. The relativization of the
+ * given URI against this URI is computed as follows:
+ *
+ * 1. If either this URI or the given URI are opaque, or if the scheme and
+ * authority components of the two URIs are not identical, or if the path
+ * of this URI is not a prefix of the path of the given URI, then the
+ * given URI is returned.
+ * 2. Otherwise a new relative hierarchical URI is constructed with query
+ * and fragment components taken from the given URI and with a path
+ * component computed by removing this URI's path from the beginning of
+ * the given URI's path.
+ *
+ * @param uri - The URI to be relativized against this URI
+ * @returns The resulting URI
+ */
+ URI relativize( const URI& uri ) const;
+
+ /**
+ * Constructs a new URI by parsing the given string and then resolving it
+ * against this URI.
+ *
+ * This convenience method works as if invoking it were equivalent to
+ * evaluating the expression resolve( URI::create( str ) ).
+ * @param str - The string to be parsed into a URI
+ * @returns The resulting URI
+ * @throws IllegalArgumentException - If the given string violates RFC 2396
+ */
+ URI resolve( const std::string& str )
+ throw ( lang::exceptions::IllegalArgumentException );
+
+ /**
+ * Resolves the given URI against this URI.
+ *
+ * If the given URI is already absolute, or if this URI is opaque, then a
+ * copy of the given URI is returned.
+ *
+ * If the given URI's fragment component is defined, its path component is
+ * empty, and its scheme, authority, and query components are undefined, then
+ * a URI with the given fragment but with all other components equal to those
+ * of this URI is returned. This allows a URI representing a standalone
+ * fragment reference, such as "#foo", to be usefully resolved against a base
+ * URI.
+ *
+ * Otherwise this method constructs a new hierarchical URI in a manner
+ * consistent with RFC 2396, section 5.2; that is:
+ *
+ * 1. A new URI is constructed with this URI's scheme and the given URI's
+ * query and fragment components.
+ * 2. If the given URI has an authority component then the new URI's authority
+ * and path are taken from the given URI.
+ * 3. Otherwise the new URI's authority component is copied from this URI,
+ * and its path is computed as follows:
+ *
+ * 1. If the given URI's path is absolute then the new URI's path is
+ * taken from the given URI.
+ * 2. Otherwise the given URI's path is relative, and so the new URI's
+ * path is computed by resolving the path of the given URI against the
+ * path of this URI. This is done by concatenating all but the last
+ * segment of this URI's path, if any, with the given URI's path and
+ * then normalizing the result as if by invoking the normalize method.
+ *
+ * The result of this method is absolute if, and only if, either this URI is
+ * absolute or the given URI is absolute.
+ * @param uri - The URI to be resolved against this URI
+ * @returns The resulting URI
+ */
+ URI resolve( const URI& uri );
+
+ /**
+ * Returns the content of this URI as a string.
+ *
+ * If this URI was created by invoking one of the constructors in this class
+ * then a string equivalent to the original input string, or to the string
+ * computed from the originally-given components, as appropriate, is returned.
+ * Otherwise this URI was created by normalization, resolution, or
+ * relativization, and so a string is constructed from this URI's components
+ * according to the rules specified in RFC 2396, section 5.2, step 7.
+ * @returns the string form of this URI
+ */
+ std::string toString() const;
+
+ /**
+ * Constructs a URL from this URI.
+ *
+ * This convenience method works as if invoking it were equivalent to
+ * evaluating the expression new URL(this.toString()) after first checking
+ * that this URI is absolute.
+ * @returns A URL constructed from this URI
+ * @throws IllegalArgumentException - If this URL is not absolute
+ * @throws MalformedURLException - If a protocol handler for the URL could not
+ * be found, or if some other error occurred while constructing the URL
+ */
+ URL toURL() const
+ throw ( MalformedURLException, lang::exceptions::IllegalArgumentException );
+
+ public: // Static Methods
+
+ /**
+ * Creates a URI by parsing the given string.
+ * This convenience factory method works as if by invoking the URI(string)
+ * constructor; any URISyntaxException thrown by the constructor is caught
+ * and wrapped in a new IllegalArgumentException object, which is then thrown.
+ * @param uri - URI string to parse
+ * @throws IllegalArgumentException
+ */
+ static URI create( const std::string uri )
+ throw ( lang::exceptions::IllegalArgumentException );
+
+ private:
+
+ // Parses a URI string and fills in the member data, throws a
+ // URISyntaxException if things fail
+ void parseURI( const std::string& uri ) throw ( URISyntaxException );
+
+ /*
+ * Quote illegal chars for each component, but not the others
+ *
+ * @param component java.lang.String the component to be converted @param
+ * legalset java.lang.String the legal character set allowed in the
+ * component s @return java.lang.String the converted string
+ */
+ std::string quoteComponent( const std::string& component,
+ const std::string& legalset );
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_URI_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URISyntaxException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URISyntaxException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URISyntaxException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URISyntaxException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,158 @@
+/*
+ * 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 _DECAF_NET_URISYNTAXEXCEPTION_H_
+#define _DECAF_NET_URISYNTAXEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace net{
+
+ class DECAF_API URISyntaxException : public lang::Exception {
+ private:
+
+ std::string reason;
+ std::string input;
+ int index;
+
+ public:
+
+ /**
+ * Default Constructor
+ */
+ URISyntaxException() throw() {
+ this->reason = "";
+ this->input = "";
+ this->index = -1;
+ }
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ URISyntaxException( const Exception& ex ) throw() : Exception() {
+
+ *(Exception*)this = ex;
+ this->reason = "";
+ this->input = "";
+ this->index = -1;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ URISyntaxException( const URISyntaxException& ex ) throw() : Exception() {
+
+ *(Exception*)this = ex;
+ this->reason = ex.getReason();
+ this->input = ex.getInput();
+ this->index = ex.getIndex();
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the input string that caused the error
+ * and the reason for the error.
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param input uri string
+ * @param reason string for the failure.
+ * @param list of primitives that are formatted into the message
+ */
+ URISyntaxException( const char* file, const int lineNumber,
+ const std::string& input,
+ const std::string& reason ) throw () : Exception() {
+
+ this->reason = reason;
+ this->input = input;
+ this->index = -1;
+
+ const char * message = "Input: %s, Reason it failed: %s";
+ this->setMessage( message, input.c_str(), reason.c_str() );
+
+ // Set the first mark for this exception.
+ setMark( file, lineNumber );
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the input string that caused the error
+ * and the reason for the error.
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param input uri string
+ * @param reason string for the failure.
+ * @param index in the uri string where the error occured.
+ */
+ URISyntaxException( const char* file, const int lineNumber,
+ const std::string& input,
+ const std::string& reason,
+ int index ) throw () : Exception() {
+
+ this->reason = reason;
+ this->input = input;
+ this->index = index;
+
+ const char * message = "Input: %s, Index %d resulted in this error: %s";
+ this->setMessage( message, input.c_str(), index, reason.c_str() );
+
+ // 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 URISyntaxException* clone() const {
+ return new URISyntaxException( *this );
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~URISyntaxException() throw() {}
+
+ /**
+ * @returns the Input string that cause this exception or ""
+ */
+ std::string getInput() const {
+ return input;
+ }
+
+ /**
+ * @returns the Reason given for this failure, or ""
+ */
+ std::string getReason() const {
+ return reason;
+ }
+
+ /**
+ * @returns the index in the input string where the error occured or -1
+ */
+ int getIndex() const {
+ return index;
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_URISYNTAXEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URL.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URL.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URL.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URL.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,25 @@
+/*
+ * 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 "URL.h"
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+URL::URL() {
+}
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URL.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URL.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URL.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URL.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,36 @@
+/*
+ * 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 _DECAF_NET_URL_H_
+#define _DECAF_NET_URL_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace net{
+
+ class DECAF_API URL {
+ public:
+
+ URL();
+ virtual ~URL() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_URL_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,25 @@
+/*
+ * 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 "URLDecoder.h"
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+URLDecoder::URLDecoder() {
+}
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URLDecoder.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,36 @@
+/*
+ * 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 _DECAF_NET_URLDECODER_H_
+#define _DECAF_NET_URLDECODER_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace net{
+
+ class DECAF_API URLDecoder {
+ public:
+
+ URLDecoder();
+ virtual ~URLDecoder() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_URLDECODER_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,25 @@
+/*
+ * 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 "URLEncoder.h"
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+URLEncoder::URLEncoder() {
+}
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/URLEncoder.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,36 @@
+/*
+ * 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 _DECAF_NET_URLENCODER_H_
+#define _DECAF_NET_URLENCODER_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace net{
+
+ class DECAF_API URLEncoder {
+ public:
+
+ URLEncoder();
+ virtual ~URLEncoder() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_URLENCODER_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownHostException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownHostException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownHostException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownHostException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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 _DECAF_NET_UNKNOWNHOSTEXCEPTION_H_
+#define _DECAF_NET_UNKNOWNHOSTEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace net{
+
+ class DECAF_API UnknownHostException : public io::IOException {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ UnknownHostException() throw() {}
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ UnknownHostException( const Exception& ex ) throw()
+ : io::IOException()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ UnknownHostException( const UnknownHostException& ex ) throw()
+ : io::IOException()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. 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 message to report
+ * @param list of primitives that are formatted into the message
+ */
+ UnknownHostException( const char* file, const int lineNumber,
+ const char* msg, ... ) throw ()
+ : io::IOException()
+ {
+ 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 UnknownHostException* clone() const {
+ return new UnknownHostException( *this );
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~UnknownHostException() throw() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_UNKNOWNHOSTEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownServiceException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownServiceException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownServiceException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/UnknownServiceException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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 _DECAF_NET_UNKNOWNSERVICEEXCEPTION_H_
+#define _DECAF_NET_UNKNOWNSERVICEEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace net{
+
+ class DECAF_API UnknownServiceException : public io::IOException {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ UnknownServiceException() throw() {}
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ UnknownServiceException( const Exception& ex ) throw()
+ : io::IOException()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ UnknownServiceException( const UnknownServiceException& ex ) throw()
+ : io::IOException()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. 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 message to report
+ * @param list of primitives that are formatted into the message
+ */
+ UnknownServiceException( const char* file, const int lineNumber,
+ const char* msg, ... ) throw ()
+ : io::IOException()
+ {
+ 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 UnknownServiceException* clone() const {
+ return new UnknownServiceException( *this );
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~UnknownServiceException() throw() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_UNKNOWNSERVICEEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/nio/Buffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/nio/Buffer.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/nio/Buffer.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/nio/Buffer.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,137 @@
+/*
+ * 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 "Buffer.h"
+
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+
+using namespace decaf;
+using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer::Buffer( std::size_t capacity ) {
+ this->_capacity = capacity;
+ this->_limit = capacity;
+ this->_position = 0;
+ this->_mark = 0;
+ this->_markSet = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer::Buffer( const Buffer& other ) {
+
+ this->_capacity = other._capacity;
+ this->_limit = other._limit;
+ this->_position = other._position;
+ this->_mark = other._mark;
+ this->_markSet = other._markSet;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer& Buffer::position( std::size_t newPosition )
+ throw( lang::exceptions::IllegalArgumentException ) {
+
+ if( newPosition > this->_limit ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__,
+ "Buffer::position - New Position is greater than set limit" );
+ }
+
+ this->_position = newPosition;
+ if( this->_markSet && ( this->_mark > newPosition ) ) {
+ this->_mark = 0;
+ this->_markSet = false;
+ }
+
+ return *this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer& Buffer::limit( std::size_t newLimit ) throw( IllegalArgumentException ) {
+
+ if( newLimit > this->capacity() ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__,
+ "Buffer::limit - new limit is larger than the capacity." );
+ }
+
+ this->_limit = newLimit;
+ if( this->_position > newLimit ) {
+ this->_position = newLimit;
+ }
+
+ if( this->_markSet && ( this->_mark > newLimit ) ) {
+ this->_mark = 0;
+ this->_markSet = false;
+ }
+
+ return *this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer& Buffer::mark() {
+
+ this->_mark = this->_position;
+ this->_markSet = true;
+
+ return *this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer& Buffer::reset() throw ( InvalidMarkException ) {
+
+ if( !this->_markSet ) {
+ throw InvalidMarkException(
+ __FILE__, __LINE__,
+ "Buffer::reset - Buffer has not been Marked." );
+ }
+
+ this->_position = this->_mark;
+
+ return *this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer& Buffer::clear() {
+
+ this->_position = 0;
+ this->_mark = 0;
+ this->_markSet = false;
+ this->_limit = this->capacity();
+ return *this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer& Buffer::flip() {
+
+ this->_limit = this->_position;
+ this->_position = 0;
+ this->_mark = 0;
+ this->_markSet = false;
+ return *this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Buffer& Buffer::rewind() {
+
+ this->_position = 0;
+ this->_mark = 0;
+ this->_markSet = false;
+ return *this;
+}