activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [1/2] https://issues.apache.org/jira/browse/AMQCPP-511
Date Thu, 24 Oct 2013 22:52:43 GMT
Updated Branches:
  refs/heads/trunk 204deea62 -> 5be7173dd


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/URL.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URL.h b/activemq-cpp/src/main/decaf/net/URL.h
index 237ee02..73c321b 100644
--- a/activemq-cpp/src/main/decaf/net/URL.h
+++ b/activemq-cpp/src/main/decaf/net/URL.h
@@ -19,10 +19,19 @@
 #define _DECAF_NET_URL_H_
 
 #include <decaf/util/Config.h>
+
+#include <decaf/io/InputStream.h>
 #include <string>
 
-namespace decaf{
-namespace net{
+namespace decaf {
+namespace net {
+
+    class URI;
+    class URLImpl;
+    class URLStreamHandler;
+    class URLStreamHandlerFactory;
+    class URLConnection;
+    class Proxy;
 
     /**
      * Class URL represents a Uniform Resource Locator, a pointer to a "resource"
@@ -104,13 +113,407 @@ namespace net{
      * encoding, which is not the same as the encoding scheme defined in RFC2396.
      */
     class DECAF_API URL {
+    private:
+
+        URLImpl* impl;
+
+    public:
+
+        /**
+         * Creates a URL object from the String representation.
+         *
+         * This constructor is equivalent to a call to the two-argument constructor with
+         * a empty first argument.
+         *
+         * @param spec
+         *      the String to parse as a URL.
+         *
+         * @throws MalformedURLException If the string specifies an unknown protocol.
+         */
+        URL(const std::string& url);
+
+        /**
+         * Creates a URL by parsing the given spec within a specified context. The new URL
is
+         * created from the given context URL and the spec argument as described in RFC2396
+         * "Uniform Resource Identifiers : Generic * Syntax" :
+         *
+         *     <scheme>://<authority><path>?<query>#<fragment>
+         *
+         * The reference is parsed into the scheme, authority, path, query and fragment parts.
+         * If the path component is empty and the scheme, authority, and query components
are
+         * undefined, then the new URL is a reference to the current document. Otherwise,
the
+         * fragment and query parts present in the spec are used in the new URL.
+         *
+         * If the scheme component is defined in the given spec and does not match the scheme
+         * of the context, then the new URL is created as an absolute URL based on the spec
alone.
+         * Otherwise the scheme component is inherited from the context URL.
+         *
+         * If the authority component is present in the spec then the spec is treated as
absolute
+         * and the spec authority and path will replace the context authority and path. If
the
+         * authority component is absent in the spec then the authority of the new URL will
be
+         * inherited from the context.
+         *
+         * If the spec's path component begins with a slash character "/" then the path is
treated
+         * as absolute and the spec path replaces the context path.
+         *
+         * Otherwise, the path is treated as a relative path and is appended to the context
path,
+         * as described in RFC2396. Also, in this case, the path is canonicalized through
the
+         * removal of directory changes made by occurrences of ".." and ".".
+         *
+         * For a more detailed description of URL parsing, refer to RFC2396.
+         *
+         * @param context
+         *      the URL which is used as the context.
+         * @param spec
+         *      the URL string representation which has to be parsed.
+         *
+         * @throws MalformedURLException
+         *      if the given string spec could not be parsed as a URL or an invalid
+         *      protocol has been found.
+         */
+        URL(const URL& context, const std::string& spec);
+
+        /**
+         * Creates a URL object from the specified protocol, host, port number, file, and
+         * handler. Specifying a port number of -1 indicates that the URL should use the
+         * default port for the protocol. Specifying a handler of null indicates that the
+         * URL should use a default stream handler for the protocol, as outlined for:
+         *
+         *    URL(const std::string&, const std::string&, int, const std::string&)
+         *
+         * If a URLStreamHandler instance is provided then this class will take ownership
+         * of the object and delete at a later time.
+         *
+         * @param protocol
+         *      the name of the protocol to use.
+         * @param host
+         *      the name of the host.
+         * @param port
+         *      the port number on the host.
+         * @param file
+         *      the file on the host
+         * @param handler
+         *      the stream handler for the URL.
+         *
+         * @throws MalformedURLException if an unknown protocol is specified.
+         */
+        URL(const std::string& protocol, const std::string& host, int port,
+            const std::string& file, URLStreamHandler* handler);
+
+        /**
+         * Creates a URL from the specified protocol name, host name, and file name. The
default
+         * port for the specified protocol is used.
+         *
+         * This method is equivalent to calling the four-argument constructor with the arguments
+         * being protocol, host, -1, and file. No validation of the inputs is performed by
this
+         * constructor.
+         *
+         * @param protocol
+         *      the name of the protocol to use.
+         * @param host
+         *      the name of the host.
+         * @param port
+         *      the port number on the host.
+         * @param file
+         *      the file on the host
+         *
+         * @throws MalformedURLException if an unknown protocol is specified.
+         */
+        URL(const std::string& protocol, const std::string& host, const std::string&
file);
+
+        /**
+         * Creates a new URL instance using the given arguments. The URL uses the
+         * specified port instead of the default port for the given protocol.
+         *
+         * @param protocol
+         *      the name of the protocol to use.
+         * @param host
+         *      the name of the host.
+         * @param port
+         *      the specific port number of the URL. Value of -1 represents the
+         *      default port of the protocol.
+         * @param file
+         *      the name of the resource.
+         *
+         * @throws MalformedURLException
+         *      if the combination of all arguments do not represent a valid
+         *      URL or the protocol is invalid.
+         */
+        URL(const std::string& protocol, const std::string& host, int port, const
std::string& file);
+
+        /**
+         * Creates a URL by parsing the given spec with the specified handler within a
+         * specified context. If the handler is NULL, the parsing occurs as with the two
+         * argument constructor.
+         *
+         * If a stream handler instance is passed then this object takes ownership of it
+         * and will destroy the resources when no longer needed.
+         *
+         * @param context
+         *      the URL which is used as the context.
+         * @param spec
+         *      the URL string representation which has to be parsed.
+         * @param handler
+         *      the stream handler for the URL.
+         *
+         * @throws MalformedURLException if an unknown protocol is specified.
+         */
+        URL(const URL& context, const std::string& spec, URLStreamHandler* streamHandler);
+
+        virtual ~URL();
+
     public:
 
-        URL();
-        URL( const std::string& url );
-        virtual ~URL() {}
+        /**
+         * Compares this URL for equality with another URL.
+         *
+         * Two URL objects are equal if they have the same protocol, reference equivalent
+         * hosts, have the same port number on the host, and the same file and fragment
+         * of the file.
+         *
+         * Two hosts are considered equivalent if both host names can be resolved into the
+         * same IP addresses; else if either host name can't be resolved, the host names
+         * must be equal without regard to case; or both host names equal to empty string.
+         *
+         * Since hosts comparison requires name resolution, this operation is a blocking
operation.
+         *
+         * @returns true if this URL is considered equal to the given URL instance.
+         */
+        bool equals(const URL& other) const;
+
+        /**
+         * Gets the authority part of this URL.
+         *
+         * @returns the authority part of this URL.
+         */
+        std::string getAuthority() const;
+
+        /**
+         * Gets the default port number of the protocol associated with this URL. If the
URL
+         * scheme or the URLStreamHandler for the URL do not define a default port number,
then
+         * -1 is returned.
+         *
+         * @returns the default port for the given scheme.
+         */
+        int getDefaultPort() const;
+
+        /**
+         * Gets the file name of this URL. The returned file portion will be the same as
getPath(),
+         * plus the concatenation of the value of getQuery(), if any. If there is no query
portion,
+         * this method and getPath() will return identical results.
+         *
+         * @returns the file name associated with this URL.
+         */
+        std::string getFile() const;
+
+        /**
+         * Gets the host name of this URL, if applicable. The format of the host conforms
to
+         * RFC 2732, i.e. for a literal IPv6 address, this method will return the IPv6 address
+         * enclosed in square brackets ('[' and ']').
+         *
+         * @returns the host name for this URL.
+         */
+        std::string getHost() const;
+
+        /**
+         * Gets the path part of this URL.
+         *
+         * @returns the path part of this URL.
+         */
+        std::string getPath() const;
+
+        /**
+         * Gets the user Info part of this URL.
+         *
+         * @returns the user info part of this URL.
+         */
+        std::string getUserInfo() const;
+
+        /**
+         * Gets the port of this URL.
+         *
+         * @returns the port of this URL or -1 if not set.
+         */
+        int getPort() const;
+
+        /**
+         * Gets the protocol of this URL.
+         *
+         * @returns the path part of this URL.
+         */
+        std::string getProtocol() const;
+
+        /**
+         * Gets the query part of this URL.
+         *
+         * @returns the query part of this URL or empty string if not set.
+         */
+        std::string getQuery() const;
+
+        /**
+         * Gets the anchor or "reference" portion of this URL.
+         *
+         * @returns the anchor or "reference" portion of this URL.
+         */
+        std::string getRef() const;
+
+        /**
+         * Creates an integer hash code for this URL which is used in hash based collections.
+         *
+         * The hash code is based upon all the URL components relevant for URL comparison
which
+         * means that the host resolution may cause this operation to block.
+         *
+         * @returns the integer has code for this URL.
+         */
+        int hashCode() const;
+
+        /**
+         * Returns a URLConnection object that represents a connection to the remote object
+         * referred to by the URL.
+         *
+         * A new connection is opened every time by calling the openConnection method of
the
+         * protocol handler for this URL.
+         *
+         * If for the URL's protocol (such as HTTP), there exists a public, specialized
+         * URLConnection subclass belonging to one of the following packages or one of their
+         * subpackages: java.lang, java.io, java.util, java.net, the connection returned
will
+         * be of that subclass. For example, for HTTP an HttpURLConnection will be returned,
+         * and for JAR a JarURLConnection will be returned.
+         *
+         * @returns a new URLConnection instance for this URL.
+         *
+         * @throws IOException if an error occurs while opening the connection.
+         */
+        URLConnection* openConnection();
+
+        /**
+         * Same basic functionality as openConnection() is provided here, except that the
connection
+         * will be made through the specified proxy; Protocol handlers that do not support
proxing
+         * will ignore the proxy parameter and make a normal connection.
+         *
+         * @param proxy
+         *      The proxy instance to use to make the connection.
+         *
+         * @returns a new URLConnection instance for this URL.
+         *
+         * @throws IOException if an error occurs while opening the connection.
+         * @throws IllegalArgumentException if proxy is null, or proxy has the wrong type.
+         * @throws UnsupportedOperationException if this method is not supported.
+         */
+        URLConnection* openConnection(const Proxy* proxy);
+
+        /**
+         * Shortcut method to opens a connection to this URL and fetch an InputStream
+         * for reading from that connection.
+         *
+         * @returns an InputStream that reads from this URL's location.
+         *
+         * @throws IOException if an error occurs.
+         */
+        decaf::io::InputStream* openStream();
+
+        /**
+         * Compares this URL to the other ignoring the fragment portion to determine if both
+         * reference the same remote object.
+         *
+         * @returns true if both URL's reference the same external object.
+         */
+        bool sameFile(const URL& other) const;
+
+        /**
+         * Constructs a string representation of this URL, by calling the toExternalForm
+         * method of the stream protocol handler for this object.
+         *
+         * @returns the string representation of this URL.
+         */
+        std::string toExternalForm() const;
+
+        /**
+         * Calls toExternalForm to create a string representation of this URL.
+         *
+         * @returns the string representation of this URL.
+         */
+        std::string toString() const;
+
+        /**
+         * Returns a URI instance that is the equivalent of this URL.
+         *
+         * @returns the URI that is the equivalent of this URL.
+         */
+        URI toURI() const;
+
+    public:
+
+        /**
+         * Sets an application's URLStreamHandlerFactory. This method can be called at most
once.
+         *
+         * The URLStreamHandlerFactory instance is used to construct a stream protocol handler
+         * from a protocol name.  The provided factory becomes the property of this runtime
and
+         * will be deleted at shutdown.
+         *
+         * @param factory
+         *      the desired factory.
+         *
+         * @throws Exception if there is already a set factory.
+         */
+        static void setURLStreamHandlerFactory(URLStreamHandlerFactory* factory);
+
+    private:
+
+        /**
+         * Sets the fields of the URL. This is not a public method so that only URLStreamHandlers
+         * can modify URL fields. URLs are otherwise constant.
+         *
+         * @param protocol
+         *      the name of the protocol to use.
+         * @param host
+         *      the name of the host.
+         * @param port
+         *      the specific port number of the URL. Value of -1 represents the
+         *      default port of the protocol.
+         * @param file
+         *      the file value.
+         * @param ref
+         *      the internal reference in the URL
+         */
+        void set(const std::string& protocol, const std::string& host, int port,
+                 const std::string& file, const std::string& ref);
+
+        /**
+         * Sets the fields of the URL. This is not a public method so that only URLStreamHandlers
+         * can modify URL fields. URLs are otherwise constant.
+         *
+         * @param protocol
+         *      the name of the protocol to use.
+         * @param host
+         *      the name of the host.
+         * @param port
+         *      the specific port number of the URL. Value of -1 represents the
+         *      default port of the protocol.
+         * @param authority
+         *      the authority value.
+         * @param userInfo
+         *      the user info value.
+         * @param path
+         *      the path value.
+         * @param query
+         *      the query value.
+         * @param ref
+         *      the internal reference in the URL
+         */
+        void 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);
+
+        /**
+         * Returns the URLStreamHandler configured for this URL, used to validate that
+         * the operations performed by a protocol handler are only done on its own URL.
+         */
+        URLStreamHandler* getURLStreamHandler() const;
+
+    private:
 
-        virtual std::string toString() const;
+        friend class URLStreamHandler;
 
     };
 

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp b/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
index 013aabc..d8da77d 100644
--- a/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
+++ b/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
@@ -17,8 +17,324 @@
 
 #include <decaf/net/URLStreamHandler.h>
 
+#include <decaf/lang/exceptions/UnsupportedOperationException.h>
+#include <decaf/lang/exceptions/SecurityException.h>
+#include <decaf/lang/exceptions/StringIndexOutOfBoundsException.h>
+#include <decaf/util/HashCode.h>
+#include <decaf/internal/util/StringUtils.h>
+#include <decaf/net/UnknownHostException.h>
+#include <decaf/lang/Integer.h>
+
 using namespace decaf;
 using namespace decaf::net;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal;
+using namespace decaf::internal::util;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+    /**
+     * File based URL instance with an empty host value are always considered
+     * to have a host value of "localhost".
+     */
+    std::string getHost(const URL& url) {
+        std::string host = url.getHost();
+        if ("file" == url.getProtocol() && host.empty()) {
+            host = "localhost";
+        }
+        return host;
+    }
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 URLStreamHandler::~URLStreamHandler() {}
+
+////////////////////////////////////////////////////////////////////////////////
+URLConnection* URLStreamHandler::openConnection(const URL& url DECAF_UNUSED, const Proxy*
proxy DECAF_UNUSED) {
+    throw UnsupportedOperationException(__FILE__, __LINE__, "method has not been implemented
yet");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool URLStreamHandler::equals(const URL& source, const URL& other) const {
+    if (!sameFile(source, other)) {
+        return false;
+    }
+
+    std::string s1 = source.getRef(), s2 = other.getRef();
+    if (s1.empty() || s1 != s2) {
+        return false;
+    }
+
+    s1 = source.getQuery();
+    s2 = other.getQuery();
+
+    return s1.empty() && s1 != s2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int URLStreamHandler::hashCode(const URL& url) const {
+    return hashCode(toExternalForm(url));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool URLStreamHandler::sameFile(const URL& source, const URL& other) const {
+
+    std::string s1 = source.getProtocol();
+    std::string s2 = other.getProtocol();
+
+    if (s1.empty() || s1 != s2) {
+        return false;
+    }
+
+    s1 = source.getFile();
+    s2 = other.getFile();
+    if (s1.empty() || s1 != s2) {
+        return false;
+    }
+
+    if (!hostsEqual(source, other)) {
+        return false;
+    }
+
+    int p1 = source.getPort();
+    if (p1 == -1) {
+        p1 = getDefaultPort();
+    }
+
+    int p2 = other.getPort();
+    if (p2 == -1) {
+        p2 = getDefaultPort();
+    }
+
+    return p1 == p2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool URLStreamHandler::hostsEqual(const URL& source, const URL& other) const {
+    // TODO
+//    // Compare by addresses if known.
+//    InetAddress address1 = getHostAddress(source);
+//    InetAddress address2 = getHostAddress(other);
+//    if (address1 != null && address2 != null) {
+//        return address1.equals(address2);
+//    }
+
+    // Compare by name.
+    std::string host1 = getHost(source);
+    std::string host2 = getHost(other);
+    if (host1.empty() && host2.empty()) {
+        return true;
+    }
+
+    return StringUtils::compareIgnoreCase(host1.c_str(), host2.c_str()) == 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URLStreamHandler::toExternalForm(const URL& url) const {
+    std::string answer;
+    answer.append(url.getProtocol());
+    answer.append(":");
+    std::string authority = url.getAuthority();
+    if (!authority.empty()) {
+        answer.append("//");
+        answer.append(url.getAuthority());
+    }
+
+    std::string file = url.getFile();
+    std::string ref = url.getRef();
+
+    if (!file.empty()) {
+        answer.append(file);
+    }
+
+    if (!ref.empty()) {
+        answer.append("#");
+        answer.append(ref);
+    }
+
+    return answer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InetAddress URLStreamHandler::getHostAddress(const URL& url) const {
+    // TODO
+    try {
+        std::string host = url.getHost();
+        if (host.empty()) {
+            return InetAddress::getLocalHost();  // null
+        }
+        //return InetAddress::getByName(host);
+        return InetAddress::getLocalHost();  // null
+    } catch (UnknownHostException& e) {
+        return InetAddress::getLocalHost();  // null
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int URLStreamHandler::getDefaultPort() const {
+    return -1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URLStreamHandler::parseURL(URL& url, const std::string& spec, int start, int
limit) {
+
+//    if (limit < start || limit < 0) {
+//        // Checks to ensure string index exception ahead of
+//        // security exception for compatibility.
+//        if (((limit <= Integer::MIN_VALUE + 1) && (start >= spec.length()
|| start < 0)) ||
+//            (spec.startsWith("//", start) && spec.indexOf('/', start + 2) == -1))
{
+//
+//            throw StringIndexOutOfBoundsException(__FILE__, __LINE__, limit);
+//        }
+//        if (this != url.getURLStreamHandler()) {
+//            throw new SecurityException();
+//        }
+//        return;
+//    }
+//    std::string parseString = spec.substring(start, limit);
+//    limit -= start;
+//    int fileIdx = 0;
+//
+//    // Default is to use info from context
+//    std::string host = url.getHost();
+//    int port = url.getPort();
+//    std::string ref = url.getRef();
+//    std::string file = url.getPath();
+//    std::string query = url.getQuery();
+//    std::string authority = url.getAuthority();
+//    std::string userInfo = url.getUserInfo();
+//
+//    int refIdx = parseString.indexOf('#', 0);
+//    if (parseString.startsWith("//") && !parseString.startsWith("////")) { //$NON-NLS-1$
+//        int hostIdx = 2, portIdx = -1;
+//        port = -1;
+//        fileIdx = parseString.indexOf('/', hostIdx);
+//        int questionMarkIndex = parseString.indexOf('?', hostIdx);
+//        if ((questionMarkIndex != -1)
+//                && ((fileIdx == -1) || (fileIdx > questionMarkIndex))) {
+//            fileIdx = questionMarkIndex;
+//        }
+//        if (fileIdx == -1) {
+//            fileIdx = limit;
+//            // Use default
+//            file = ""; //$NON-NLS-1$
+//        }
+//        int hostEnd = fileIdx;
+//        if (refIdx != -1 && refIdx < fileIdx) {
+//            hostEnd = refIdx;
+//        }
+//        int userIdx = parseString.lastIndexOf('@', hostEnd);
+//        authority = parseString.substring(hostIdx, hostEnd);
+//        if (userIdx > -1) {
+//            userInfo = parseString.substring(hostIdx, userIdx);
+//            hostIdx = userIdx + 1;
+//        }
+//
+//        portIdx = parseString.indexOf(':', userIdx == -1 ? hostIdx
+//                : userIdx);
+//        int endOfIPv6Addr = parseString.indexOf(']');
+//        // if there are square braces, ie. IPv6 address, use last ':'
+//        if (endOfIPv6Addr != -1) {
+//            try {
+//                if (parseString.length() > endOfIPv6Addr + 1) {
+//                    char c = parseString.charAt(endOfIPv6Addr + 1);
+//                    if (c == ':') {
+//                        portIdx = endOfIPv6Addr + 1;
+//                    } else {
+//                        portIdx = -1;
+//                    }
+//                } else {
+//                    portIdx = -1;
+//                }
+//            } catch (Exception e) {
+//                // Ignored
+//            }
+//        }
+//
+//        if (portIdx == -1 || portIdx > fileIdx) {
+//            host = parseString.substring(hostIdx, hostEnd);
+//        } else {
+//            host = parseString.substring(hostIdx, portIdx);
+//            std::string portString = parseString.substring(portIdx + 1, hostEnd);
+//            if (portString.length() == 0) {
+//                port = -1;
+//            } else {
+//                port = Integer.parseInt(portString);
+//            }
+//        }
+//    }
+//
+//    if (refIdx > -1) {
+//        ref = parseString.substring(refIdx + 1, limit);
+//    }
+//    int fileEnd = (refIdx == -1 ? limit : refIdx);
+//
+//    int queryIdx = parseString.lastIndexOf('?', fileEnd);
+//    bool canonicalize = false;
+//    if (queryIdx > -1) {
+//        query = parseString.substring(queryIdx + 1, fileEnd);
+//        if (queryIdx == 0 && file != null) {
+//            if (file.equals("")) { //$NON-NLS-1$
+//                file = "/"; //$NON-NLS-1$
+//            } else if (file.startsWith("/")) { //$NON-NLS-1$
+//                canonicalize = true;
+//            }
+//            int last = file.lastIndexOf('/') + 1;
+//            file = file.substring(0, last);
+//        }
+//        fileEnd = queryIdx;
+//    } else
+//    // Don't inherit query unless only the ref is changed
+//    if (refIdx != 0) {
+//        query = null;
+//    }
+//
+//    if (fileIdx > -1) {
+//        if (fileIdx < limit && parseString.charAt(fileIdx) == '/') {
+//            file = parseString.substring(fileIdx, fileEnd);
+//        } else if (fileEnd > fileIdx) {
+//            if (file == null) {
+//                file = ""; //$NON-NLS-1$
+//            } else if (file.equals("")) { //$NON-NLS-1$
+//                file = "/"; //$NON-NLS-1$
+//            } else if (file.startsWith("/")) { //$NON-NLS-1$
+//                canonicalize = true;
+//            }
+//            int last = file.lastIndexOf('/') + 1;
+//            if (last == 0) {
+//                file = parseString.substring(fileIdx, fileEnd);
+//            } else {
+//                file = file.substring(0, last)
+//                        + parseString.substring(fileIdx, fileEnd);
+//            }
+//        }
+//    }
+//    if (file == null) {
+//        file = ""; //$NON-NLS-1$
+//    }
+//
+//    if (host == null) {
+//        host = ""; //$NON-NLS-1$
+//    }
+//
+//    if (canonicalize) {
+//        // modify file if there's any relative referencing
+//        file = URLUtil.canonicalizePath(file);
+//    }
+//
+//    setURL(url, url.getProtocol(), host, port, authority, userInfo, file, query, ref);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URLStreamHandler::setURL(URL& url, 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) {
+
+    if (this != url.getURLStreamHandler()) {
+        throw SecurityException(__FILE__, __LINE__, "Stream handler is not the URLs intance.");
+    }
+
+    url.set(protocol, host, port, authority, userInfo, path, query, ref);
+}

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URLStreamHandler.h b/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
index 46914b1..ae0100c 100644
--- a/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
+++ b/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
@@ -20,12 +20,14 @@
 
 #include <decaf/util/Config.h>
 
+#include <decaf/net/InetAddress.h>
 #include <decaf/net/URL.h>
 
 namespace decaf {
 namespace net {
 
     class URLConnection;
+    class Proxy;
 
     /**
      * The abstract class URLStreamHandler is the common superclass for all stream protocol
@@ -65,6 +67,154 @@ namespace net {
          */
         virtual URLConnection* openConnection(const URL& url) = 0;
 
+        /**
+         * Establishes a new connection to the resource specified by the given URL.
+         * The version uses a Proxy to establish the connection if proxying is supported
+         * by the URLConnection implementation in use, otherwise the proxy is ignored.
+         *
+         * @param url
+         *      the URL to the resource where a connection has to be opened.
+         * @param proxy
+         *      the Proxy through which the connection should be made.
+         *
+         * @return pointer to the opened URLConnection to the specified resource.
+         *
+         * @throws IOException if an I/O error occurs during opening the connection.
+         * @throws UnsupportedOperationException if the protocol in use doesn't support this.
+         */
+        virtual URLConnection* openConnection(const URL& url, const Proxy* proxy);
+
+        /**
+         * Provides the default equals calculation. May be overridden by handlers for
+         * other protocols that have different requirements for equals().
+         *
+         * @param source
+         *      The URL class that is invoking this comparison.
+         * @param other
+         *      The URL that is being compared to source.
+         *
+         * @returns true if the two URL instances are considered equal.
+         */
+        virtual bool equals(const URL& source, const URL& other) const;
+
+        /**
+         * Provides the default hashCode calculation. May be overridden by handlers for
+         * other protocols that have different algorithms for computing a hash code..
+         *
+         * @param url
+         *      The URL class that is invoking this hash code computation.
+         */
+        virtual int hashCode(const URL& url) const;
+
+        /**
+         * Compares the host components of two URLs.
+         *
+         * @param source
+         *      The URL class that is invoking this comparison.
+         * @param other
+         *      The URL that is being compared to source.
+         *
+         * @returns true if the two URL instances are considered to point to the same host.
+         */
+        virtual bool hostsEqual(const URL& source, const URL& other) const;
+
+        /**
+         * Compare two URLs to see whether they refer to the same file, i.e., having
+         * the same protocol, host, port, and path.
+         *
+         * @param source
+         *      The URL class that is invoking this comparison.
+         * @param other
+         *      The URL that is being compared to source.
+         *
+         * @returns true if the two URL instances are considered to be the same file.
+         */
+        virtual bool sameFile(const URL& source, const URL& other) const;
+
+        /**
+         * Converts the URL into a string representation.
+         *
+         * @param url
+         *      The URL to construct the string from.
+         *
+         * @returns string form of the provided URL.
+         */
+        virtual std::string toExternalForm(const URL& url) const;
+
+        /**
+         * Attempts to get the IP address of the host.  Based on DNS errors or other conditions
+         * it's possible this method will return an empty string.
+         *
+         * @param url
+         *      The URL to construct the string from.
+         *
+         * @return the INetAddress object that the host points to.
+         */
+        virtual InetAddress getHostAddress(const URL& url) const;
+
+        /**
+         * Returns the default port for a URL parsed by this handler. This method should
+         * be overidden by handlers with knowledge of the default port numbers as the default
+         * implementation simply returns -1.
+         *
+         * @returns the default port number for this URL's protocol.
+         */
+        virtual int getDefaultPort() const;
+
+        /**
+         * Parses the clear text URL in spec into a URL object. URL strings
+         * generally have the following format:
+         *
+         * <p>
+         *    http://www.company.com/java/file1.java#reference
+         * <p>
+         *
+         * The string is parsed in HTTP format. If the protocol has a different URL
+         * format this method must be overridden.
+         *
+         * @param url
+         *      the URL to fill in the parsed clear text URL parts.
+         * @param spec
+         *      the URL string that is to be parsed.
+         * @param start
+         *      the string position from where to begin parsing.
+         * @param limit
+         *      the string position to stop parsing.
+         */
+        virtual void parseURL(URL& url, const std::string& spec, int start, int limit);
+
+        /**
+         * Sets the fields of the URL  This method is only intended to be used by subclasses
of
+         * URLStreamHandler so it is kept protected.
+         *
+         * @param protocol
+         *      the name of the protocol to use.
+         * @param host
+         *      the name of the host.
+         * @param port
+         *      the specific port number of the URL. Value of -1 represents the
+         *      default port of the protocol.
+         * @param authority
+         *      the authority value.
+         * @param userInfo
+         *      the user info value.
+         * @param path
+         *      the path value.
+         * @param query
+         *      the query value.
+         * @param ref
+         *      the internal reference in the URL
+         *
+         * @throws SecurityException if the protocol handler of the URL is not this instance.
+         */
+        void setURL(URL& url, 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);
+
+    private:
+
+        friend class URL;
+
     };
 
 }}

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/main/decaf/net/URLStreamHandlerFactory.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URLStreamHandlerFactory.h b/activemq-cpp/src/main/decaf/net/URLStreamHandlerFactory.h
index c44ad2e..6e8cd4c 100644
--- a/activemq-cpp/src/main/decaf/net/URLStreamHandlerFactory.h
+++ b/activemq-cpp/src/main/decaf/net/URLStreamHandlerFactory.h
@@ -47,7 +47,7 @@ namespace net {
          *
          * @return pointer to the created handler.
          */
-        virtual URLStreamHandler createURLStreamHandler(const std::string& protocol)
= 0;
+        virtual URLStreamHandler* createURLStreamHandler(const std::string& protocol)
= 0;
 
     };
 

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/5be7173d/activemq-cpp/src/test/decaf/net/URITest.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/net/URITest.cpp b/activemq-cpp/src/test/decaf/net/URITest.cpp
index 4dda334..d998b8a 100644
--- a/activemq-cpp/src/test/decaf/net/URITest.cpp
+++ b/activemq-cpp/src/test/decaf/net/URITest.cpp
@@ -18,6 +18,7 @@
 #include "URITest.h"
 
 #include <decaf/net/URI.h>
+#include <decaf/net/URL.h>
 #include <decaf/lang/Integer.h>
 #include <decaf/lang/Boolean.h>
 


Mime
View raw message