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 2013/10/25 00:52:44 UTC
[2/2] git commit: https://issues.apache.org/jira/browse/AMQCPP-511
https://issues.apache.org/jira/browse/AMQCPP-511
Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/5be7173d
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/5be7173d
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/5be7173d
Branch: refs/heads/trunk
Commit: 5be7173ddc8f20889e4a073fcc5d20c486366dcc
Parents: 204deea
Author: Timothy Bish <ta...@gmai.com>
Authored: Thu Oct 24 18:52:33 2013 -0400
Committer: Timothy Bish <ta...@gmai.com>
Committed: Thu Oct 24 18:52:33 2013 -0400
----------------------------------------------------------------------
activemq-cpp/src/main/Makefile.am | 9 +
.../src/main/decaf/internal/net/URIType.cpp | 61 +++
.../src/main/decaf/internal/net/URIType.h | 82 ++--
.../src/main/decaf/internal/net/URLType.cpp | 38 ++
.../src/main/decaf/internal/net/URLType.h | 220 +++++++++
activemq-cpp/src/main/decaf/lang/String.cpp | 79 +--
activemq-cpp/src/main/decaf/lang/String.h | 33 +-
.../lang/exceptions/InvalidStateException.h | 32 +-
.../decaf/lang/exceptions/SecurityException.cpp | 66 +++
.../decaf/lang/exceptions/SecurityException.h | 116 +++++
.../StringIndexOutOfBoundsException.cpp | 79 +++
.../StringIndexOutOfBoundsException.h | 139 ++++++
activemq-cpp/src/main/decaf/net/Proxy.cpp | 26 +
activemq-cpp/src/main/decaf/net/Proxy.h | 38 ++
activemq-cpp/src/main/decaf/net/URI.cpp | 1 +
activemq-cpp/src/main/decaf/net/URI.h | 46 +-
activemq-cpp/src/main/decaf/net/URL.cpp | 477 ++++++++++++++++++-
activemq-cpp/src/main/decaf/net/URL.h | 415 +++++++++++++++-
.../src/main/decaf/net/URLStreamHandler.cpp | 316 ++++++++++++
.../src/main/decaf/net/URLStreamHandler.h | 150 ++++++
.../main/decaf/net/URLStreamHandlerFactory.h | 2 +-
activemq-cpp/src/test/decaf/net/URITest.cpp | 1 +
22 files changed, 2299 insertions(+), 127 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/Makefile.am
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/Makefile.am b/activemq-cpp/src/main/Makefile.am
index 77cf0b6..efc214b 100644
--- a/activemq-cpp/src/main/Makefile.am
+++ b/activemq-cpp/src/main/Makefile.am
@@ -351,6 +351,8 @@ cc_sources = \
decaf/internal/net/SocketFileDescriptor.cpp \
decaf/internal/net/URIEncoderDecoder.cpp \
decaf/internal/net/URIHelper.cpp \
+ decaf/internal/net/URIType.cpp \
+ decaf/internal/net/URLType.cpp \
decaf/internal/net/ssl/DefaultSSLContext.cpp \
decaf/internal/net/ssl/DefaultSSLServerSocketFactory.cpp \
decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp \
@@ -475,6 +477,8 @@ cc_sources = \
decaf/lang/exceptions/NumberFormatException.cpp \
decaf/lang/exceptions/OutOfMemoryError.cpp \
decaf/lang/exceptions/RuntimeException.cpp \
+ decaf/lang/exceptions/SecurityException.cpp \
+ decaf/lang/exceptions/StringIndexOutOfBoundsException.cpp \
decaf/lang/exceptions/UnsupportedOperationException.cpp \
decaf/net/BindException.cpp \
decaf/net/ConnectException.cpp \
@@ -491,6 +495,7 @@ cc_sources = \
decaf/net/NoRouteToHostException.cpp \
decaf/net/PortUnreachableException.cpp \
decaf/net/ProtocolException.cpp \
+ decaf/net/Proxy.cpp \
decaf/net/ServerSocket.cpp \
decaf/net/ServerSocketFactory.cpp \
decaf/net/Socket.cpp \
@@ -1020,6 +1025,7 @@ h_sources = \
decaf/internal/net/URIEncoderDecoder.h \
decaf/internal/net/URIHelper.h \
decaf/internal/net/URIType.h \
+ decaf/internal/net/URLType.h \
decaf/internal/net/ssl/DefaultSSLContext.h \
decaf/internal/net/ssl/DefaultSSLServerSocketFactory.h \
decaf/internal/net/ssl/DefaultSSLSocketFactory.h \
@@ -1152,6 +1158,8 @@ h_sources = \
decaf/lang/exceptions/NumberFormatException.h \
decaf/lang/exceptions/OutOfMemoryError.h \
decaf/lang/exceptions/RuntimeException.h \
+ decaf/lang/exceptions/SecurityException.h \
+ decaf/lang/exceptions/StringIndexOutOfBoundsException.h \
decaf/lang/exceptions/UnsupportedOperationException.h \
decaf/net/BindException.h \
decaf/net/ConnectException.h \
@@ -1168,6 +1176,7 @@ h_sources = \
decaf/net/NoRouteToHostException.h \
decaf/net/PortUnreachableException.h \
decaf/net/ProtocolException.h \
+ decaf/net/Proxy.h \
decaf/net/ServerSocket.h \
decaf/net/ServerSocketFactory.h \
decaf/net/Socket.h \
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/internal/net/URIType.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/net/URIType.cpp b/activemq-cpp/src/main/decaf/internal/net/URIType.cpp
new file mode 100644
index 0000000..ab595fe
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/internal/net/URIType.cpp
@@ -0,0 +1,61 @@
+/*
+ * 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 "URIType.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+
+////////////////////////////////////////////////////////////////////////////////
+URIType::URIType(const std::string& source) : source(source),
+ scheme(),
+ schemeSpecificPart(),
+ authority(),
+ userinfo(),
+ host(),
+ port(-1),
+ path(),
+ query(),
+ fragment(),
+ opaque(false),
+ absolute(false),
+ serverAuthority(false),
+ valid(false),
+ hashCode(-1) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URIType::URIType() : source(),
+ scheme(),
+ schemeSpecificPart(),
+ authority(),
+ userinfo(),
+ host(),
+ port( -1 ),
+ path(),
+ query(),
+ fragment(),
+ opaque(false),
+ absolute(false),
+ serverAuthority(false),
+ valid(false),
+ hashCode(-1) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URIType::~URIType() {}
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/internal/net/URIType.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/net/URIType.h b/activemq-cpp/src/main/decaf/internal/net/URIType.h
index 7ed6015..cc68789 100644
--- a/activemq-cpp/src/main/decaf/internal/net/URIType.h
+++ b/activemq-cpp/src/main/decaf/internal/net/URIType.h
@@ -45,42 +45,14 @@ namespace net {
bool absolute;
bool serverAuthority;
bool valid;
+ int hashCode;
public:
- URIType( const std::string& source ) : source( source ),
- scheme(),
- schemeSpecificPart(),
- authority(),
- userinfo(),
- host(),
- port( -1 ),
- path(),
- query(),
- fragment(),
- opaque( false ),
- absolute( false ),
- serverAuthority( false ),
- valid( false ) {
- }
-
- URIType() : source(),
- scheme(),
- schemeSpecificPart(),
- authority(),
- userinfo(),
- host(),
- port( -1 ),
- path(),
- query(),
- fragment(),
- opaque( false ),
- absolute( false ),
- serverAuthority( false ),
- valid( false ) {
- }
+ URIType();
+ URIType(const std::string& source);
- virtual ~URIType() {}
+ virtual ~URIType();
/**
* Gets the source URI string that was parsed to obtain this URIType
@@ -96,7 +68,7 @@ namespace net {
* instance and the resulting data,
* @param source - the source URI string
*/
- void setSource( const std::string& source ) {
+ void setSource(const std::string& source) {
this->source = source;
}
@@ -112,7 +84,7 @@ namespace net {
* Sets the Scheme of the URI, e.g. scheme ("http"/"ftp"/...).
* @param scheme - scheme part string.
*/
- void setScheme( const std::string& scheme ) {
+ void setScheme(const std::string& scheme) {
this->scheme = scheme;
}
@@ -128,7 +100,7 @@ namespace net {
* Sets the Scheme Specific Part of the URI.
* @param schemeSpecificPart - scheme specific part string.
*/
- void setSchemeSpecificPart( const std::string& schemeSpecificPart ) {
+ void setSchemeSpecificPart(const std::string& schemeSpecificPart) {
this->schemeSpecificPart = schemeSpecificPart;
}
@@ -144,7 +116,7 @@ namespace net {
* Sets the Authority of the URI.
* @param authority Authority part string.
*/
- void setAuthority( const std::string& authority ) {
+ void setAuthority(const std::string& authority) {
this->authority = authority;
}
@@ -162,7 +134,7 @@ namespace net {
* http://user:passwd@host:port/
* @param userinfo - user info part string.
*/
- void setUserInfo( const std::string& userinfo ) {
+ void setUserInfo(const std::string& userinfo) {
this->userinfo = userinfo;
}
@@ -178,7 +150,7 @@ namespace net {
* Sets the Host name part of the URI.
* @param host - Host name part string.
*/
- void setHost( const std::string& host ) {
+ void setHost(const std::string& host) {
this->host = host;
}
@@ -194,7 +166,7 @@ namespace net {
* Sets the port part of the URI.
* @param port - port part string, -1 if not set.
*/
- void setPort( int port ) {
+ void setPort(int port) {
this->port = port;
}
@@ -210,7 +182,7 @@ namespace net {
* Sets the Path part of the URI.
* @param path - Path part string.
*/
- void setPath( const std::string& path ) {
+ void setPath(const std::string& path) {
this->path = path;
}
@@ -226,7 +198,7 @@ namespace net {
* Sets the Query part of the URI.
* @param query - Query part string.
*/
- void setQuery( const std::string& query ) {
+ void setQuery(const std::string& query) {
this->query = query;
}
@@ -242,7 +214,7 @@ namespace net {
* Sets the Fragment part of the URI.
* @param fragment - Fragment part string.
*/
- void setFragment( const std::string& fragment ) {
+ void setFragment(const std::string& fragment) {
this->fragment = fragment;
}
@@ -258,7 +230,7 @@ namespace net {
* Sets if the URI is Opaque.
* @param opaque true if opaque.
*/
- void setOpaque( bool opaque ) {
+ void setOpaque(bool opaque) {
this->opaque = opaque;
}
@@ -274,7 +246,7 @@ namespace net {
* Sets if the URI is Absolute.
* @param absolute - true if Absolute.
*/
- void setAbsolute( bool absolute ) {
+ void setAbsolute(bool absolute) {
this->absolute = absolute;
}
@@ -290,7 +262,7 @@ namespace net {
* Sets if the URI is a Server Authority.
* @param serverAuthority - true if Server Authority.
*/
- void setServerAuthority( bool serverAuthority ) {
+ void setServerAuthority(bool serverAuthority) {
this->serverAuthority = serverAuthority;
}
@@ -308,10 +280,28 @@ namespace net {
* parsed and all relevant data fields have been set.
* @param valid - true if the URIType contains valid data.
*/
- void setValid( bool valid ) {
+ void setValid(bool valid) {
this->valid = valid;
}
+ /**
+ * Gets the computed hashCode for this URIType or return -1 if non is set
+ *
+ * @returns the hash code for this URIType instance or -1 if not set.
+ */
+ int getHashCode() const {
+ return this->hashCode;
+ }
+
+ /**
+ * Sets the hash code for this URIType instance.
+ *
+ * @param hashCode
+ * The new hash code that's been computed for this URIType instance.
+ */
+ void setHashCode(int hashCode) {
+ this->hashCode = hashCode;
+ }
};
}}}
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/internal/net/URLType.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/net/URLType.cpp b/activemq-cpp/src/main/decaf/internal/net/URLType.cpp
new file mode 100644
index 0000000..db086a9
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/internal/net/URLType.cpp
@@ -0,0 +1,38 @@
+/*
+ * 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 "URLType.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+
+////////////////////////////////////////////////////////////////////////////////
+URLType::URLType() : file(),
+ protocol(),
+ host(),
+ port(-1),
+ authority(),
+ userInfo(),
+ path(),
+ query(),
+ ref(),
+ hashCode(-1) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URLType::~URLType() {}
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/internal/net/URLType.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/net/URLType.h b/activemq-cpp/src/main/decaf/internal/net/URLType.h
new file mode 100644
index 0000000..dc20188
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/internal/net/URLType.h
@@ -0,0 +1,220 @@
+/*
+ * 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_INTERNAL_NET_URLTYPE_H_
+#define _DECAF_INTERNAL_NET_URLTYPE_H_
+
+#include <string>
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+
+ /**
+ * Basic type object that holds data that composes a given URL
+ */
+ class DECAF_API URLType {
+ private:
+
+ std::string file;
+ std::string protocol;
+ std::string host;
+ int port;
+ std::string authority;
+ std::string userInfo;
+ std::string path;
+ std::string query;
+ std::string ref;
+ int hashCode;
+
+ public:
+
+ URLType();
+
+ virtual ~URLType();
+
+ /**
+ * Gets the File of the URL.
+ * @return File part string.
+ */
+ std::string getFile() const {
+ return file;
+ }
+
+ /**
+ * Sets the File of the URL.
+ * @param File Authority part string.
+ */
+ void setFile(const std::string& file) {
+ this->file = file;
+ }
+
+ /**
+ * Gets the protocol of the URL, e.g. protocol ("http"/"ftp"/...).
+ * @return protocol part string.
+ */
+ std::string getProtocol() const {
+ return protocol;
+ }
+
+ /**
+ * Sets the protocol of the URL, e.g. protocol ("http"/"ftp"/...).
+ * @param protocol - protocol part string.
+ */
+ void setProtocol(const std::string& protocol) {
+ this->protocol = protocol;
+ }
+
+ /**
+ * Gets the Authority of the URL.
+ * @return Authority part string.
+ */
+ std::string getAuthority() const {
+ return authority;
+ }
+
+ /**
+ * Sets the Authority of the URL.
+ * @param authority Authority part string.
+ */
+ void setAuthority(const std::string& authority) {
+ this->authority = authority;
+ }
+
+ /**
+ * Gets the user info part of the URL, e.g. user name, as in
+ * http://user:passwd@host:port/
+ * @return user info part string.
+ */
+ std::string getUserInfo() const {
+ return userInfo;
+ }
+
+ /**
+ * Sets the user info part of the URL, e.g. user name, as in
+ * http://user:passwd@host:port/
+ *
+ * @param userInfo - user info part string.
+ */
+ void setUserInfo(const std::string& userInfo) {
+ this->userInfo = userInfo;
+ }
+
+ /**
+ * Gets the Host name part of the URL.
+ * @return Host name part string.
+ */
+ std::string getHost() const {
+ return host;
+ }
+
+ /**
+ * Sets the Host name part of the URL.
+ * @param host - Host name part string.
+ */
+ void setHost(const std::string& host) {
+ this->host = host;
+ }
+
+ /**
+ * Gets the port part of the URL.
+ * @return port part string, -1 if not set.
+ */
+ int getPort() const {
+ return port;
+ }
+
+ /**
+ * Sets the port part of the URL.
+ * @param port - port part string, -1 if not set.
+ */
+ void setPort(int port) {
+ this->port = port;
+ }
+
+ /**
+ * Gets the Path part of the URL.
+ * @return Path part string.
+ */
+ std::string getPath() const {
+ return path;
+ }
+
+ /**
+ * Sets the Path part of the URL.
+ * @param path - Path part string.
+ */
+ void setPath(const std::string& path) {
+ this->path = path;
+ }
+
+ /**
+ * Gets the Query part of the URL.
+ * @return Query part string.
+ */
+ std::string getQuery() const {
+ return query;
+ }
+
+ /**
+ * Sets the Query part of the URL.
+ * @param query - Query part string.
+ */
+ void setQuery(const std::string& query) {
+ this->query = query;
+ }
+
+ /**
+ * Gets the Ref part of the URL.
+ * @return Ref part string.
+ */
+ std::string getRef() const {
+ return ref;
+ }
+
+ /**
+ * Sets the Ref part of the URL.
+ * @param ref - Ref part string.
+ */
+ void setRef(const std::string& ref) {
+ this->ref = ref;
+ }
+
+ /**
+ * Gets the computed hashCode for this URLType or return -1 if non is set
+ *
+ * @returns the hash code for this URLType instance or -1 if not set.
+ */
+ int getHashCode() const {
+ return this->hashCode;
+ }
+
+ /**
+ * Sets the hash code for this URLType instance.
+ *
+ * @param hashCode
+ * The new hash code that's been computed for this URLType instance.
+ */
+ void setHashCode(int hashCode) {
+ this->hashCode = hashCode;
+ }
+ };
+
+}}}
+
+#endif /* _DECAF_INTERNAL_NET_URLTYPE_H_ */
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/lang/String.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/String.cpp b/activemq-cpp/src/main/decaf/lang/String.cpp
index 5f615c4..44d6e14 100644
--- a/activemq-cpp/src/main/decaf/lang/String.cpp
+++ b/activemq-cpp/src/main/decaf/lang/String.cpp
@@ -45,10 +45,10 @@ namespace lang{
public:
- Contents() : value(), length( 0 ), offset( 0 ) {
+ Contents() : value(), length(0), offset(0) {
}
- Contents( int length ) : value( length ), length( length ), offset( 0 ) {
+ Contents( int length ) : value(length), length(length), offset(0) {
}
};
@@ -60,7 +60,7 @@ String::String() : contents(new Contents()) {
}
////////////////////////////////////////////////////////////////////////////////
-String::String( const String& source ) : contents(new Contents(source.length())) {
+String::String(const String& source) : contents(new Contents(source.length())) {
// TODO
// load the passed string into the contents value.
@@ -68,7 +68,7 @@ String::String( const String& source ) : contents(new Contents(source.length()))
}
////////////////////////////////////////////////////////////////////////////////
-String::String( const std::string& source ) : contents(new Contents((int)source.length())) {
+String::String(const std::string& source) : contents(new Contents((int)source.length())) {
// load the passed string into the contents value.
System::arraycopy( (unsigned char*)source.c_str(), 0, contents->value.get(), 0, source.length() );
@@ -77,63 +77,63 @@ String::String( const std::string& source ) : contents(new Contents((int)source.
////////////////////////////////////////////////////////////////////////////////
String::String(const char* array, int size) : contents(new Contents) {
- if( size < 0 ) {
+ if (size < 0) {
throw IndexOutOfBoundsException(
- __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+ __FILE__, __LINE__, "size parameter out of Bounds: %d.", size);
}
- if( array == NULL ) {
+ if (array == NULL) {
throw NullPointerException(
- __FILE__, __LINE__, "Buffer pointer passed was NULL." );
+ __FILE__, __LINE__, "Buffer pointer passed was NULL.");
}
- if(size > 0) {
+ if (size > 0) {
this->contents->value = ArrayPointer<unsigned char>(size);
this->contents->length = size;
- System::arraycopy( (unsigned char*)array, 0, contents->value.get(), 0, size );
+ System::arraycopy((unsigned char*) array, 0, contents->value.get(), 0, size);
}
}
////////////////////////////////////////////////////////////////////////////////
String::String(const char* array, int size, int offset, int length) : contents(new Contents) {
- if( size < 0 ) {
+ if (size < 0) {
throw IndexOutOfBoundsException(
__FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
}
- if( offset > size || offset < 0 ) {
+ if (offset > size || offset < 0) {
throw IndexOutOfBoundsException(
__FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
}
- if( length < 0 || length > size - offset ) {
+ if (length < 0 || length > size - offset) {
throw IndexOutOfBoundsException(
__FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
}
- if( array == NULL ) {
+ if (array == NULL) {
throw NullPointerException(
__FILE__, __LINE__, "Buffer pointer passed was NULL." );
}
- if(size > 0) {
+ if (size > 0) {
this->contents->value = ArrayPointer<unsigned char>(length);
this->contents->length = length;
- System::arraycopy( (unsigned char*)array, offset, contents->value.get(), 0, length );
+ System::arraycopy((unsigned char*) array, offset, contents->value.get(), 0, length);
}
}
////////////////////////////////////////////////////////////////////////////////
String::~String() {
- try{
+ try {
delete this->contents;
}
- DECAF_CATCH_NOTHROW( Exception )
+ DECAF_CATCH_NOTHROW(Exception)
DECAF_CATCHALL_NOTHROW()
}
@@ -144,44 +144,49 @@ int String::length() const {
////////////////////////////////////////////////////////////////////////////////
bool String::isEmpty() const {
- return ( this->contents->offset + this->contents->length ) == 0;
+ return (this->contents->offset + this->contents->length) == 0;
}
////////////////////////////////////////////////////////////////////////////////
-char String::charAt( int index ) const {
+String String::trim() const {
+ return String();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+char String::charAt(int index) const {
try{
- if( index < 0 || index >= this->length() ) {
+ if (index < 0 || index >= this->length()) {
throw IndexOutOfBoundsException(
__FILE__, __LINE__, "Index given is out of bounds: %d.", index );
}
return this->contents->value[this->contents->offset + index];
}
- DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
- DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+ DECAF_CATCH_RETHROW(IndexOutOfBoundsException)
+ DECAF_CATCHALL_THROW(IndexOutOfBoundsException)
}
////////////////////////////////////////////////////////////////////////////////
-CharSequence* String::subSequence( int start DECAF_UNUSED, int end DECAF_UNUSED ) const {
+CharSequence* String::subSequence(int start DECAF_UNUSED, int end DECAF_UNUSED) const {
- try{
+ try {
- if( start > end ) {
+ if (start > end) {
throw IndexOutOfBoundsException(
__FILE__, __LINE__, "Start index is greater than end index." );
}
- if( end - start > this->length() ) {
+ if (end - start > this->length()) {
throw IndexOutOfBoundsException(
__FILE__, __LINE__, "Requested Range is greater than the String length." );
}
return NULL;
}
- DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
- DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+ DECAF_CATCH_RETHROW(IndexOutOfBoundsException)
+ DECAF_CATCHALL_THROW(IndexOutOfBoundsException)
}
////////////////////////////////////////////////////////////////////////////////
@@ -191,13 +196,13 @@ std::string String::toString() const {
return "null";
}
- return std::string( (const char*)this->contents->value.get(), this->length() );
+ return std::string((const char*) this->contents->value.get(), this->length());
}
////////////////////////////////////////////////////////////////////////////////
String String::valueOf(bool value) {
- if(value) {
+ if (value) {
return String("true");
}
@@ -206,30 +211,30 @@ String String::valueOf(bool value) {
////////////////////////////////////////////////////////////////////////////////
String String::valueOf(char value) {
- return String( &value, 1 );
+ return String(&value, 1);
}
////////////////////////////////////////////////////////////////////////////////
String String::valueOf(float value) {
- return String( Float::toString(value) );
+ return String(Float::toString(value));
}
////////////////////////////////////////////////////////////////////////////////
String String::valueOf(double value) {
- return String( Double::toString(value) );
+ return String(Double::toString(value));
}
////////////////////////////////////////////////////////////////////////////////
String String::valueOf(short value) {
- return String( Short::toString(value) );
+ return String(Short::toString(value));
}
////////////////////////////////////////////////////////////////////////////////
String String::valueOf(int value) {
- return String( Integer::toString(value) );
+ return String(Integer::toString(value));
}
////////////////////////////////////////////////////////////////////////////////
String String::valueOf(long long value) {
- return String( Long::toString(value) );
+ return String(Long::toString(value));
}
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/lang/String.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/String.h b/activemq-cpp/src/main/decaf/lang/String.h
index 8a32d45..9b99b20 100644
--- a/activemq-cpp/src/main/decaf/lang/String.h
+++ b/activemq-cpp/src/main/decaf/lang/String.h
@@ -35,12 +35,12 @@ namespace lang {
*
* @since 1.0
*/
- class DECAF_API String : public CharSequence {
+ class DECAF_API String: public CharSequence {
private:
Contents* contents;
- public: // Constructors
+ public:
/**
* Creates a new empty String object.
@@ -53,7 +53,7 @@ namespace lang {
* @param source
* The string to copy into this new String object.
*/
- String( const String& source );
+ String(const String& source);
/**
* Create a new String object that represents the given STL string
@@ -61,7 +61,7 @@ namespace lang {
* @param source
* The string to copy into this new String object.
*/
- String( const std::string& source );
+ String(const std::string& source);
/**
* Create a new String object that represents the given array of characters. The method
@@ -77,7 +77,7 @@ namespace lang {
* @throws NullPointerException if the character array parameter is NULL.
* @throws IndexOutOfBoundsException if the size parameter is negative.
*/
- String( const char* array, int size );
+ String(const char* array, int size);
/**
* Create a new String object that represents the given array of characters. The method
@@ -98,24 +98,31 @@ namespace lang {
* @throws IndexOutOfBoundsException if the size, offset or length parameter is negative
* or if the length to copy is greater than the span of size - offset.
*/
- String( const char* array, int size, int offset, int length );
+ String(const char* array, int size, int offset, int length);
virtual ~String();
public:
// TODO
- String& operator= ( const String& );
- String& operator= ( const std::string& );
+ String& operator=(const String&);
+ String& operator=(const std::string&);
- public: // String API
+ public:
/**
* @returns true if the length of this String is zero.
*/
bool isEmpty() const;
- public: // CharSequence Implementation
+ /**
+ * Returns a copy of the string, with leading and trailing whitespace omitted.
+ *
+ * @returns a copy of the string, with leading and trailing whitespace omitted.
+ */
+ String trim() const;
+
+ public:
/**
* {@inheritDoc}
@@ -125,19 +132,19 @@ namespace lang {
/**
* {@inheritDoc}
*/
- virtual char charAt( int index ) const;
+ virtual char charAt(int index) const;
/**
* {@inheritDoc}
*/
- virtual CharSequence* subSequence( int start, int end ) const;
+ virtual CharSequence* subSequence(int start, int end) const;
/**
* {@inheritDoc}
*/
virtual std::string toString() const;
- public: // Static methods.
+ public:
/**
* Returns a String that represents the value of the given boolean value.
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/lang/exceptions/InvalidStateException.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/exceptions/InvalidStateException.h b/activemq-cpp/src/main/decaf/lang/exceptions/InvalidStateException.h
index 67321ce..7b7507d 100644
--- a/activemq-cpp/src/main/decaf/lang/exceptions/InvalidStateException.h
+++ b/activemq-cpp/src/main/decaf/lang/exceptions/InvalidStateException.h
@@ -58,19 +58,25 @@ namespace exceptions {
* this message occurred. Sets the message to report, using an
* optional list of arguments to parse into the message
*
- * @param file The file name where exception occurs
- * @param lineNumber The line number where the exception occurred.
- * @param cause The exception that was the cause for this one to be thrown.
- * @param msg The message to report
- * @param ... list of primitives that are formatted into the message
+ * @param file
+ * The file name where exception occurs
+ * @param lineNumber
+ * The line number where the exception occurred.
+ * @param cause
+ * The exception that was the cause for this one to be thrown.
+ * @param msg
+ * The message to report
+ * @param ...
+ * list of primitives that are formatted into the message
*/
InvalidStateException(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...);
/**
* Constructor
*
- * @param cause Pointer to the exception that caused this one to
- * be thrown, the object is cloned caller retains ownership.
+ * @param cause
+ * Pointer to the exception that caused this one to be thrown, the
+ * object is cloned caller retains ownership.
*/
InvalidStateException(const std::exception* cause);
@@ -79,10 +85,14 @@ namespace exceptions {
* this message occurred. Sets the message to report, using an
* optional list of arguments to parse into the message
*
- * @param file The file name where exception occurs
- * @param lineNumber The line number where the exception occurred.
- * @param msg The message to report
- * @param ... list of primitives that are formatted into the message
+ * @param file
+ * The file name where exception occurs
+ * @param lineNumber
+ * The line number where the exception occurred.
+ * @param msg
+ * The message to report
+ * @param ...
+ * list of primitives that are formatted into the message
*/
InvalidStateException(const char* file, const int lineNumber, const char* msg, ...);
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.cpp b/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.cpp
new file mode 100644
index 0000000..24295a8
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.cpp
@@ -0,0 +1,66 @@
+/*
+ * 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 "SecurityException.h"
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+SecurityException::SecurityException() : Exception() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecurityException::~SecurityException() throw () {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecurityException::SecurityException(const Exception& ex) : Exception() {
+ *(Exception*) this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecurityException::SecurityException(const SecurityException& ex) : Exception() {
+ *(Exception*) this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecurityException::SecurityException(const std::exception* cause) : Exception(cause) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecurityException::SecurityException(const char* file, const int lineNumber, const char* msg, ...) : Exception() {
+
+ va_list vargs;
+ va_start(vargs, msg);
+ buildMessage(msg, vargs);
+
+ // Set the first mark for this exception.
+ setMark(file, lineNumber);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecurityException::SecurityException(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...) : Exception(cause) {
+
+ va_list vargs;
+ va_start(vargs, msg);
+ buildMessage(msg, vargs);
+
+ // Set the first mark for this exception.
+ setMark(file, lineNumber);
+}
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.h b/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.h
new file mode 100644
index 0000000..03b1d18
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/lang/exceptions/SecurityException.h
@@ -0,0 +1,116 @@
+/*
+ * 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_LANG_EXCEPTIONS_SECURITYEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_SECURITYEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf {
+namespace lang {
+namespace exceptions {
+
+ /*
+ * Thrown when an operation is requested, but the state of the object
+ * servicing the request is not correct for that request.
+ *
+ * @since 1.0
+ */
+ class DECAF_API SecurityException : public Exception {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ SecurityException();
+
+ /**
+ * Conversion Constructor from some other Exception
+ *
+ * @param ex
+ * The Exception whose data is to be copied into this one.
+ */
+ SecurityException(const Exception& ex);
+
+ /**
+ * Copy Constructor
+ *
+ * @param ex
+ * The Exception whose data is to be copied into this one.
+ */
+ SecurityException(const SecurityException& ex);
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occurred. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ *
+ * @param file
+ * The file name where exception occurs
+ * @param lineNumber
+ * The line number where the exception occurred.
+ * @param cause
+ * The exception that was the cause for this one to be thrown.
+ * @param msg
+ * The message to report
+ * @param ...
+ * list of primitives that are formatted into the message
+ */
+ SecurityException(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...);
+
+ /**
+ * Constructor
+ *
+ * @param cause
+ * Pointer to the exception that caused this one to be thrown, the
+ * object is cloned caller retains ownership.
+ */
+ SecurityException(const std::exception* cause);
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occurred. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ *
+ * @param file
+ * The file name where exception occurs
+ * @param lineNumber
+ * The line number where the exception occurred.
+ * @param msg
+ * The message to report
+ * @param ...
+ * list of primitives that are formatted into the message
+ */
+ SecurityException(const char* file, const int lineNumber, const char* msg, ...);
+
+ /**
+ * 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.
+ *
+ * @return an new Exception instance that is a copy of this one.
+ */
+ virtual SecurityException* clone() const {
+ return new SecurityException(*this);
+ }
+
+ virtual ~SecurityException() throw();
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_SECURITYEXCEPTION_H_*/
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.cpp b/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.cpp
new file mode 100644
index 0000000..913eb91
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.cpp
@@ -0,0 +1,79 @@
+/*
+ * 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 "StringIndexOutOfBoundsException.h"
+
+#include <decaf/lang/Integer.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException() : IndexOutOfBoundsException() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException(int index) : IndexOutOfBoundsException() {
+ this->setMessage("String index out of range: %d", index);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::~StringIndexOutOfBoundsException() throw () {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException(const Exception& ex) : IndexOutOfBoundsException() {
+ *(Exception*) this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException(const StringIndexOutOfBoundsException& ex) : IndexOutOfBoundsException() {
+ *(Exception*) this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException(const std::exception* cause) : IndexOutOfBoundsException(cause) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException(const char* file, const int lineNumber, const char* msg, ...) : IndexOutOfBoundsException() {
+
+ va_list vargs;
+ va_start(vargs, msg);
+ buildMessage(msg, vargs);
+
+ // Set the first mark for this exception.
+ setMark(file, lineNumber);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException(const char* file, const int lineNumber, int index) : IndexOutOfBoundsException() {
+ setMark(file, lineNumber);
+ this->setMessage("String index out of range: %d", index);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StringIndexOutOfBoundsException::StringIndexOutOfBoundsException(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...) : IndexOutOfBoundsException(cause) {
+
+ va_list vargs;
+ va_start(vargs, msg);
+ buildMessage(msg, vargs);
+
+ // Set the first mark for this exception.
+ setMark(file, lineNumber);
+}
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.h b/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.h
new file mode 100644
index 0000000..b44c0c1
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/lang/exceptions/StringIndexOutOfBoundsException.h
@@ -0,0 +1,139 @@
+/*
+ * 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_LANG_EXCEPTIONS_STRINGINDEXOUTOFBOUNDSEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_STRINGINDEXOUTOFBOUNDSEXCEPTION_H_
+
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+namespace decaf {
+namespace lang {
+namespace exceptions {
+
+ /*
+ * Thrown when an operation is requested, but the state of the object
+ * servicing the request is not correct for that request.
+ *
+ * @since 1.0
+ */
+ class DECAF_API StringIndexOutOfBoundsException : public IndexOutOfBoundsException {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ StringIndexOutOfBoundsException();
+
+ /**
+ * Create a new StringIndexOutOfBoundsException with the given index value
+ * to use to create the error message.
+ *
+ * @param index
+ * The given string index that was out of bounds.
+ */
+ StringIndexOutOfBoundsException(int index);
+
+ /**
+ * Conversion Constructor from some other Exception
+ *
+ * @param ex
+ * The Exception whose data is to be copied into this one.
+ */
+ StringIndexOutOfBoundsException(const Exception& ex);
+
+ /**
+ * Copy Constructor
+ *
+ * @param ex
+ * The Exception whose data is to be copied into this one.
+ */
+ StringIndexOutOfBoundsException(const StringIndexOutOfBoundsException& ex);
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occurred. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ *
+ * @param file
+ * The file name where exception occurs
+ * @param lineNumber
+ * The line number where the exception occurred.
+ * @param cause
+ * The exception that was the cause for this one to be thrown.
+ * @param msg
+ * The message to report
+ * @param ...
+ * list of primitives that are formatted into the message
+ */
+ StringIndexOutOfBoundsException(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...);
+
+ /**
+ * Constructor
+ *
+ * @param cause
+ * Pointer to the exception that caused this one to be thrown, the
+ * object is cloned caller retains ownership.
+ */
+ StringIndexOutOfBoundsException(const std::exception* cause);
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occurred. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ *
+ * @param file
+ * The file name where exception occurs
+ * @param lineNumber
+ * The line number where the exception occurred.
+ * @param msg
+ * The message to report
+ * @param ...
+ * list of primitives that are formatted into the message
+ */
+ StringIndexOutOfBoundsException(const char* file, const int lineNumber, const char* msg, ...);
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occurred. Sets the message to report, using the
+ * given index.
+ *
+ * @param file
+ * The file name where exception occurs
+ * @param lineNumber
+ * The line number where the exception occurred.
+ * @param index
+ * The string index that was out of bounds.
+ */
+ StringIndexOutOfBoundsException(const char* file, const int lineNumber, int index);
+
+ /**
+ * 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.
+ *
+ * @return an new Exception instance that is a copy of this one.
+ */
+ virtual StringIndexOutOfBoundsException* clone() const {
+ return new StringIndexOutOfBoundsException(*this);
+ }
+
+ virtual ~StringIndexOutOfBoundsException() throw();
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_STRINGINDEXOUTOFBOUNDSEXCEPTION_H_*/
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/Proxy.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/Proxy.cpp b/activemq-cpp/src/main/decaf/net/Proxy.cpp
new file mode 100644
index 0000000..6109c44
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/net/Proxy.cpp
@@ -0,0 +1,26 @@
+/*
+ * 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/net/Proxy.h>
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+Proxy::~Proxy() {
+}
+
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/Proxy.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/Proxy.h b/activemq-cpp/src/main/decaf/net/Proxy.h
new file mode 100644
index 0000000..2055e00
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/net/Proxy.h
@@ -0,0 +1,38 @@
+/*
+ * 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_PROXY_H_
+#define _DECAF_NET_PROXY_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace net {
+
+ /**
+ * @since 1.0
+ */
+ class Proxy {
+ public:
+
+ virtual ~Proxy();
+
+ };
+
+}}
+
+#endif /* _DECAF_NET_PROXY_H_ */
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/URI.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URI.cpp b/activemq-cpp/src/main/decaf/net/URI.cpp
index 036537e..df38265 100644
--- a/activemq-cpp/src/main/decaf/net/URI.cpp
+++ b/activemq-cpp/src/main/decaf/net/URI.cpp
@@ -19,6 +19,7 @@
#include <decaf/lang/Integer.h>
#include <decaf/lang/Character.h>
+#include <decaf/net/URL.h>
#include <decaf/internal/net/URIHelper.h>
#include <decaf/internal/util/StringUtils.h>
#include <decaf/internal/net/URIEncoderDecoder.h>
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/URI.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URI.h b/activemq-cpp/src/main/decaf/net/URI.h
index f1a667a..da3a786 100644
--- a/activemq-cpp/src/main/decaf/net/URI.h
+++ b/activemq-cpp/src/main/decaf/net/URI.h
@@ -23,13 +23,14 @@
#include <decaf/lang/exceptions/IllegalArgumentException.h>
#include <decaf/net/URISyntaxException.h>
#include <decaf/net/MalformedURLException.h>
-#include <decaf/net/URL.h>
#include <decaf/internal/net/URIType.h>
#include <string>
namespace decaf {
namespace net {
+ class URL;
+
/**
* This class represents an instance of a URI as defined by RFC 2396.
*/
@@ -205,6 +206,7 @@ namespace net {
* 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;
@@ -214,6 +216,7 @@ namespace net {
*
* 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;
@@ -224,13 +227,16 @@ namespace net {
* 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;
@@ -238,7 +244,9 @@ namespace net {
/**
* 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;
@@ -248,6 +256,7 @@ namespace net {
* 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;
@@ -256,6 +265,7 @@ namespace net {
* 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;
@@ -263,6 +273,7 @@ namespace net {
/**
* 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;
@@ -272,6 +283,7 @@ namespace net {
* 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;
@@ -298,6 +310,7 @@ namespace net {
* 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;
@@ -314,10 +327,12 @@ namespace net {
* 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.
+ * authority
+ *
+ * @throws URISyntaxException If the authority component of this URI is
+ * defined but cannot be parsed as a server-based authority.
*/
URI parseServerAuthority() const;
@@ -334,7 +349,9 @@ namespace net {
* 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
+ * @param uri
+ * The URI to be relativized against this URI
+ *
* @returns The resulting URI
*/
URI relativize(const URI& uri) const;
@@ -345,8 +362,12 @@ namespace net {
*
* 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
+ *
+ * @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) const;
@@ -384,7 +405,10 @@ namespace net {
*
* 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
+ *
+ * @param uri
+ * The URI to be resolved against this URI
+ *
* @returns The resulting URI
*/
URI resolve(const URI& uri) const;
@@ -398,6 +422,7 @@ namespace net {
* 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;
@@ -408,15 +433,16 @@ namespace net {
* 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
+ * be found, or if some other error occurred while constructing the URL
*/
URL toURL() const;
- public:
- // Static Methods
+ public: // Static Methods
/**
* Creates a URI by parsing the given string.
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/URL.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URL.cpp b/activemq-cpp/src/main/decaf/net/URL.cpp
index 8e505b2..8b003e8 100644
--- a/activemq-cpp/src/main/decaf/net/URL.cpp
+++ b/activemq-cpp/src/main/decaf/net/URL.cpp
@@ -17,19 +17,490 @@
#include "URL.h"
+#include <decaf/lang/Pointer.h>
+#include <decaf/net/URI.h>
+#include <decaf/net/URLConnection.h>
+#include <decaf/net/URLStreamHandler.h>
+#include <decaf/net/URLStreamHandlerFactory.h>
+#include <decaf/net/MalformedURLException.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+#include <decaf/internal/net/URLType.h>
+#include <decaf/util/HashMap.h>
+#include <decaf/util/concurrent/Mutex.h>
+
using namespace std;
using namespace decaf;
+using namespace decaf::io;
using namespace decaf::net;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf {
+namespace net {
+
+ class URLImpl {
+ public:
+
+ URLType url;
+ Pointer<URLStreamHandler> streamHandler;
+
+ static URLStreamHandlerFactory* streamHandlerFactory;
+ static HashMap<std::string, URLStreamHandler*> streamHandlers;
+
+ public:
+
+ URLImpl() : url(), streamHandler() {}
+
+ void initialize(const URL* context, const std::string& spec, URLStreamHandler* handler) {
+ if (handler != NULL) {
+ streamHandler.reset(handler);
+ }
+
+ if (spec.empty()) {
+ throw MalformedURLException(__FILE__, __LINE__, "spec was NULL");
+ }
+// // spec = spec.trim(); // trim
+//
+// // The spec includes a protocol if it includes a colon character
+// // before the first occurrence of a slash character. Note that,
+// // "protocol" is the field which holds this URLs protocol.
+// int index;
+// try {
+// index = spec.indexOf(':');
+// } catch (NullPointerException e) {
+// throw new MalformedURLException(e.toString());
+// }
+// int startIPv6Addr = spec.indexOf('[');
+// if (index >= 0) {
+// if ((startIPv6Addr == -1) || (index < startIPv6Addr)) {
+// protocol = spec.substring(0, index);
+// // According to RFC 2396 scheme part should match
+// // the following expression:
+// // alpha *( alpha | digit | "+" | "-" | "." )
+// char c = protocol.charAt(0);
+// boolean valid = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
+// for (int i = 1; valid && (i < protocol.length()); i++) {
+// c = protocol.charAt(i);
+// valid = ('a' <= c && c <= 'z') ||
+// ('A' <= c && c <= 'Z') ||
+// ('0' <= c && c <= '9') ||
+// (c == '+') ||
+// (c == '-') ||
+// (c == '.');
+// }
+// if (!valid) {
+// protocol = NULL;
+// index = -1;
+// } else {
+// // Ignore case in protocol names.
+// // Scheme is defined by ASCII characters.
+// protocol = Util.toASCIILowerCase(protocol);
+// }
+// }
+// }
+//
+// if (url.getProtocol().empty()) {
+// // If the context was specified, and it had the same protocol
+// // as the spec, then fill in the receiver's slots from the values
+// // in the context but still allow them to be over-ridden later
+// // by the values in the spec.
+// if (context != NULL && protocol.equals(context.getProtocol())) {
+// String cPath = context.getPath();
+// if (cPath != NULL && cPath.startsWith("/")) {
+// set(protocol, context.getHost(), context.getPort(), context
+// .getAuthority(), context.getUserInfo(), cPath,
+// context.getQuery(), NULL);
+// }
+// if (streamHandler == NULL) {
+// streamHandler = context.streamHandler;
+// }
+// }
+// } else {
+// // If the spec did not include a protocol, then the context
+// // *must* be specified. Fill in the receiver's slots from the
+// // values in the context, but still allow them to be over-ridden
+// // by the values in the ("relative") spec.
+// if (context == NULL) {
+// throw MalformedURLException(__FILE__, __LINE__, "Protocol not found: %s", spec);
+// }
+// set(context.getProtocol(), context.getHost(), context.getPort(),
+// context.getAuthority(), context.getUserInfo(), context
+// .getPath(), context.getQuery(), NULL);
+// if (streamHandler == NULL) {
+// streamHandler = context.streamHandler;
+// }
+// }
+//
+// // If the stream handler has not been determined, set it
+// // to the default for the specified protocol.
+// if (streamHandler == NULL) {
+// setupStreamHandler();
+// if (streamHandler == NULL) {
+// throw MalformedURLException(__FILE__, __LINE__, "unknown protocol: %s", url.getProtocol().c_str());
+// }
+// }
+//
+// // Let the handler parse the URL. If the handler throws
+// // any exception, throw MalformedURLException instead.
+// //
+// // Note: We want "index" to be the index of the start of the scheme
+// // specific part of the URL. At this point, it will be either
+// // -1 or the index of the colon after the protocol, so we
+// // increment it to point at either character 0 or the character
+// // after the colon.
+// try {
+// streamHandler->parseURL(*this, spec, ++index, (int) spec.length());
+// } catch (Exception& e) {
+// throw MalformedURLException(__FILE__, __LINE__, e.getMessage());
+// }
+//
+// if (url.getPort() < -1) {
+// throw MalformedURLException(__FILE__, __LINE__, "port out of range: %d", url.getPort());
+// }
+ }
+
+ void initialize(const std::string& protocol, const std::string& host, int port,
+ const std::string& file, const URLStreamHandler* handler) {
+
+ if (port < -1) {
+ throw MalformedURLException(__FILE__, __LINE__, "Port out of range: %d", port);
+ }
+
+// if (host != NULL && host.indexOf(":") != -1 && host.charAt(0) != '[') {
+// host = "[" + host + "]";
+// }
+//
+// if (protocol == NULL) {
+// throw NullPointerException(
+// __FILE__, __LINE__, "Unknown protocol: %s", "NULL");
+// }
+//
+// url.setProtocol(protocol);
+// url.setHost(host);
+// url.setPort(port);
+//
+// // Set the fields from the arguments. Handle the case where the
+// // passed in "file" includes both a file and a reference part.
+// std::size_t index = -1;
+// index = file.find_first_of("#", file.find_last_of("/"));
+// if (index != string::npos) {
+// url.setFile(file.substr(0, index));
+// url.setRef(file.substr(index + 1));
+// } else {
+// url.setFile(file);
+// }
+// fixURL(false);
+//
+// // Set the stream handler for the URL either to the handler argument if it was
+// // specified, or to the default for the receiver's protocol if the handler was NULL.
+// if (handler == NULL) {
+// setupStreamHandler();
+// if (streamHandler == NULL) {
+// throw MalformedURLException(
+// __FILE__, __LINE__, "Unknown protocol: %s", protocol.c_str());
+// }
+// } else {
+// streamHandler = handler;
+// }
+ }
+
+ void fixURL(bool fixHost) {
+// int index;
+// if (!url.getHost().empty()) {
+// url.setAuthority(url.getHost());
+// if (url.getPort() != -1) {
+// url.setAuthority(url.getAuthority() + ":" + Integer::toString(url.getPort()));
+// }
+// }
+//
+// if (fixHost) {
+// if (host != NULL && (index = host.lastIndexOf('@')) > -1) {
+// userInfo = host.substring(0, index);
+// host = host.substring(index + 1);
+// } else {
+// url.setUserInfo("");
+// }
+// }
+//
+// if (file != NULL && (index = file.indexOf('?')) > -1) {
+// query = file.substring(index + 1);
+// path = file.substring(0, index);
+// } else {
+// url.setQuery("");
+// url.setPath(url.getFile());
+// }
+ }
+
+ /**
+ * Sets the receiver's stream handler to one which is appropriate for its
+ * protocol. Throws a MalformedURLException if no reasonable handler is
+ * available.
+ * <p>
+ * Note that this will overwrite any existing stream handler with the new
+ * one. Senders must check if the streamHandler is NULL before calling the
+ * method if they do not want this behavior (a speed optimization).
+ */
+ void setupStreamHandler() {
+// // Check for a cached (previously looked up) handler for the requested protocol.
+// streamHandler = streamHandlers.get(protocol);
+// if (streamHandler != NULL) {
+// return;
+// }
+//
+// // If there is a stream handler factory, then attempt to
+// // use it to create the handler.
+// if (streamHandlerFactory != NULL) {
+// streamHandler = streamHandlerFactory.createURLStreamHandler(protocol);
+// if (streamHandler != NULL) {
+// streamHandlers.put(protocol, streamHandler);
+// return;
+// }
+// }
+//
+// // Check if there is a list of packages which can provide handlers.
+// // If so, then walk this list looking for an applicable one.
+// String packageList = AccessController
+// .doPrivileged(new PriviAction<String>(
+// "java.protocol.handler.pkgs")); //$NON-NLS-1$
+// if (packageList != NULL) {
+// StringTokenizer st = new StringTokenizer(packageList, "|"); //$NON-NLS-1$
+// while (st.hasMoreTokens()) {
+// String className = st.nextToken() + "." + protocol + ".Handler"; //$NON-NLS-1$ //$NON-NLS-2$
+//
+// try {
+// streamHandler = (URLStreamHandler) Class.forName(className,
+// true, ClassLoader.getSystemClassLoader())
+// .newInstance();
+// if (streamHandler != NULL) {
+// streamHandlers.put(protocol, streamHandler);
+// }
+// return;
+// } catch (IllegalAccessException e) {
+// } catch (InstantiationException e) {
+// } catch (ClassNotFoundException e) {
+// }
+// }
+// }
+//
+// // No one else has provided a handler, so try our internal one.
+//
+// String className = "org.apache.harmony.luni.internal.net.www.protocol." + protocol //$NON-NLS-1$
+// + ".Handler"; //$NON-NLS-1$
+// try {
+// streamHandler = (URLStreamHandler) Class.forName(className)
+// .newInstance();
+// } catch (IllegalAccessException e) {
+// } catch (InstantiationException e) {
+// } catch (ClassNotFoundException e) {
+// }
+// if (streamHandler != NULL) {
+// streamHandlers.put(protocol, streamHandler);
+// }
+ }
+ };
+
+ URLStreamHandlerFactory* URLImpl::streamHandlerFactory;
+ HashMap<std::string, URLStreamHandler*> URLImpl::streamHandlers;
+}}
+
+////////////////////////////////////////////////////////////////////////////////
+URL::URL(const std::string& url) : impl(new URLImpl) {
+ impl->initialize(NULL, url, NULL);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URL::URL(const URL& context, const std::string& spec) : impl(new URLImpl) {
+ impl->initialize(&context, spec, NULL);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URL::URL(const URL& context, const std::string& spec, URLStreamHandler* streamHandler) : impl(new URLImpl) {
+ impl->initialize(&context, spec, streamHandler);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URL::URL(const std::string& protocol, const std::string& host, int port,
+ const std::string& file, URLStreamHandler* handler) : impl(new URLImpl) {
+ impl->initialize(protocol, host, port, file, handler);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URL::URL(const std::string& protocol, const std::string& host, const std::string& file) : impl(new URLImpl) {
+ impl->initialize(protocol, host, -1, file, NULL);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URL::URL(const std::string& protocol, const std::string& host, int port, const std::string& file) : impl() {
+ impl->initialize(protocol, host, port, file, NULL);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URL::~URL() {
+ try {
+ delete impl;
+ }
+ DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool URL::equals(const URL& other) const {
+ return impl->streamHandler->equals(*this, other);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URL::getAuthority() const {
+ return impl->url.getAuthority();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int URL::getDefaultPort() const {
+ return impl->streamHandler->getDefaultPort();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URL::getFile() const {
+ return impl->url.getFile();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URL::getHost() const {
+ return impl->url.getHost();
+}
////////////////////////////////////////////////////////////////////////////////
-URL::URL() {
+std::string URL::getPath() const {
+ return impl->url.getPath();
}
////////////////////////////////////////////////////////////////////////////////
-URL::URL( const std::string& url DECAF_UNUSED ) {
+std::string URL::getUserInfo() const {
+ return impl->url.getUserInfo();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int URL::getPort() const {
+ return impl->url.getPort();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URL::getProtocol() const {
+ return impl->url.getProtocol();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URL::getQuery() const {
+ return impl->url.getQuery();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URL::getRef() const {
+ return impl->url.getRef();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int URL::hashCode() const {
+ int hashCode = impl->url.getHashCode();
+ if (hashCode == -1) {
+ hashCode = impl->streamHandler->hashCode(*this);
+ impl->url.setHashCode(hashCode);
+ }
+
+ return hashCode;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URLConnection* URL::openConnection() {
+ return impl->streamHandler->openConnection(*this);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URLConnection* URL::openConnection(const Proxy* proxy) {
+ if (proxy == NULL) {
+ throw IllegalArgumentException(__FILE__, __LINE__, "proxy should not be NULL");
+ }
+
+ return impl->streamHandler->openConnection(*this, proxy);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InputStream* URL::openStream() {
+ return NULL; // TODO figure out Connection lifetime
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URL::toExternalForm() const {
+ if (impl->streamHandler == NULL) {
+ return std::string("unknown protocol(") + getProtocol() + ")://" + getHost() + getFile();
+ }
+ return impl->streamHandler->toExternalForm(*this);
}
////////////////////////////////////////////////////////////////////////////////
std::string URL::toString() const {
- return "";
+ return toExternalForm();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URI URL::toURI() const {
+ return URI(this->toString());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URL::set(const std::string& protocol, const std::string& host, int port,
+ const std::string& file, const std::string& ref) {
+
+ if (impl->url.getProtocol().empty()) {
+ impl->url.setProtocol(protocol);
+ }
+
+ impl->url.setHost(host);
+ impl->url.setFile(file);
+ impl->url.setPort(port);
+ impl->url.setRef(ref);
+ impl->url.setHashCode(-1);
+
+ impl->fixURL(true);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URL::set(const std::string& protocol, const std::string& host, int port,
+ const std::string& authority, const std::string& userInfo,
+ const std::string& path, const std::string& query, const std::string& ref) {
+
+ std::string filePart = path;
+ if (!query.empty()) {
+ if (!filePart.empty()) {
+ filePart = filePart + "?" + query;
+ } else {
+ filePart = "?" + query;
+ }
+ }
+ set(protocol, host, port, filePart, ref);
+
+ impl->url.setAuthority(authority);
+ impl->url.setUserInfo(userInfo);
+ impl->url.setPath(path);
+ impl->url.setQuery(query);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URLStreamHandler* URL::getURLStreamHandler() const {
+ return this->impl->streamHandler.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URL::setURLStreamHandlerFactory(URLStreamHandlerFactory* factory) {
+
+ if (URLImpl::streamHandlerFactory != NULL) {
+ throw Exception(__FILE__, __LINE__, "Attempt to set factory more than once");
+ }
+
+ // TODO thread safe
+ URLImpl::streamHandlers.clear();
+ URLImpl::streamHandlerFactory = factory;
}