Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) OSGi Alliance (2002, 2008). All Rights Reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.osgi.service.url; |
| 18 | |
| 19 | import java.net.*; |
| 20 | |
| 21 | /** |
| 22 | * Abstract implementation of the <code>URLStreamHandlerService</code> |
| 23 | * interface. All the methods simply invoke the corresponding methods on |
| 24 | * <code>java.net.URLStreamHandler</code> except for <code>parseURL</code> |
| 25 | * and <code>setURL</code>, which use the <code>URLStreamHandlerSetter</code> |
| 26 | * parameter. Subclasses of this abstract class should not need to override the |
| 27 | * <code>setURL</code> and <code>parseURL(URLStreamHandlerSetter,...)</code> |
| 28 | * methods. |
| 29 | * |
| 30 | * @ThreadSafe |
| 31 | * @version $Revision: 5673 $ |
| 32 | */ |
| 33 | public abstract class AbstractURLStreamHandlerService extends URLStreamHandler |
| 34 | implements URLStreamHandlerService { |
| 35 | /** |
| 36 | * @see "java.net.URLStreamHandler.openConnection" |
| 37 | */ |
| 38 | public abstract URLConnection openConnection(URL u) |
| 39 | throws java.io.IOException; |
| 40 | |
| 41 | /** |
| 42 | * The <code>URLStreamHandlerSetter</code> object passed to the parseURL |
| 43 | * method. |
| 44 | */ |
| 45 | protected volatile URLStreamHandlerSetter realHandler; |
| 46 | |
| 47 | /** |
| 48 | * Parse a URL using the <code>URLStreamHandlerSetter</code> object. This |
| 49 | * method sets the <code>realHandler</code> field with the specified |
| 50 | * <code>URLStreamHandlerSetter</code> object and then calls |
| 51 | * <code>parseURL(URL,String,int,int)</code>. |
| 52 | * |
| 53 | * @param realHandler The object on which the <code>setURL</code> method |
| 54 | * must be invoked for the specified URL. |
| 55 | * @see "java.net.URLStreamHandler.parseURL" |
| 56 | */ |
| 57 | public void parseURL(URLStreamHandlerSetter realHandler, URL u, |
| 58 | String spec, int start, int limit) { |
| 59 | this.realHandler = realHandler; |
| 60 | parseURL(u, spec, start, limit); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * This method calls <code>super.toExternalForm</code>. |
| 65 | * |
| 66 | * @see "java.net.URLStreamHandler.toExternalForm" |
| 67 | */ |
| 68 | public String toExternalForm(URL u) { |
| 69 | return super.toExternalForm(u); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * This method calls <code>super.equals(URL,URL)</code>. |
| 74 | * |
| 75 | * @see "java.net.URLStreamHandler.equals(URL,URL)" |
| 76 | */ |
| 77 | public boolean equals(URL u1, URL u2) { |
| 78 | return super.equals(u1, u2); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * This method calls <code>super.getDefaultPort</code>. |
| 83 | * |
| 84 | * @see "java.net.URLStreamHandler.getDefaultPort" |
| 85 | */ |
| 86 | public int getDefaultPort() { |
| 87 | return super.getDefaultPort(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * This method calls <code>super.getHostAddress</code>. |
| 92 | * |
| 93 | * @see "java.net.URLStreamHandler.getHostAddress" |
| 94 | */ |
| 95 | public InetAddress getHostAddress(URL u) { |
| 96 | return super.getHostAddress(u); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * This method calls <code>super.hashCode(URL)</code>. |
| 101 | * |
| 102 | * @see "java.net.URLStreamHandler.hashCode(URL)" |
| 103 | */ |
| 104 | public int hashCode(URL u) { |
| 105 | return super.hashCode(u); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * This method calls <code>super.hostsEqual</code>. |
| 110 | * |
| 111 | * @see "java.net.URLStreamHandler.hostsEqual" |
| 112 | */ |
| 113 | public boolean hostsEqual(URL u1, URL u2) { |
| 114 | return super.hostsEqual(u1, u2); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * This method calls <code>super.sameFile</code>. |
| 119 | * |
| 120 | * @see "java.net.URLStreamHandler.sameFile" |
| 121 | */ |
| 122 | public boolean sameFile(URL u1, URL u2) { |
| 123 | return super.sameFile(u1, u2); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * This method calls |
| 128 | * <code>realHandler.setURL(URL,String,String,int,String,String)</code>. |
| 129 | * |
| 130 | * @see "java.net.URLStreamHandler.setURL(URL,String,String,int,String,String)" |
| 131 | * @deprecated This method is only for compatibility with handlers written |
| 132 | * for JDK 1.1. |
| 133 | */ |
| 134 | protected void setURL(URL u, String proto, String host, int port, |
| 135 | String file, String ref) { |
| 136 | realHandler.setURL(u, proto, host, port, file, ref); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * This method calls |
| 141 | * <code>realHandler.setURL(URL,String,String,int,String,String,String,String)</code>. |
| 142 | * |
| 143 | * @see "java.net.URLStreamHandler.setURL(URL,String,String,int,String,String,String,String)" |
| 144 | */ |
| 145 | protected void setURL(URL u, String proto, String host, int port, |
| 146 | String auth, String user, String path, String query, String ref) { |
| 147 | realHandler.setURL(u, proto, host, port, auth, user, path, query, ref); |
| 148 | } |
| 149 | } |