blob: e641366f3436e87191210306c6d0f5400d81c241 [file] [log] [blame]
Richard S. Hall2532cf82010-03-24 09:51:11 +00001/*
Carsten Ziegeler3314f912014-07-30 07:22:32 +00002 * Copyright (c) OSGi Alliance (2002, 2013). All Rights Reserved.
Richard S. Hall2532cf82010-03-24 09:51:11 +00003 *
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
17package org.osgi.service.url;
18
Carsten Ziegeler3314f912014-07-30 07:22:32 +000019import java.net.InetAddress;
20import java.net.URL;
21import java.net.URLConnection;
22import java.net.URLStreamHandler;
23import org.osgi.annotation.versioning.ConsumerType;
Richard S. Hall2532cf82010-03-24 09:51:11 +000024
25/**
Richard S. Halldfd78a42012-05-11 20:19:02 +000026 * Abstract implementation of the {@code URLStreamHandlerService} interface. All
27 * the methods simply invoke the corresponding methods on
28 * {@code java.net.URLStreamHandler} except for {@code parseURL} and
29 * {@code setURL}, which use the {@code URLStreamHandlerSetter} parameter.
30 * Subclasses of this abstract class should not need to override the
31 * {@code setURL} and {@code parseURL(URLStreamHandlerSetter,...)} methods.
Richard S. Hall2532cf82010-03-24 09:51:11 +000032 *
33 * @ThreadSafe
Carsten Ziegeler3314f912014-07-30 07:22:32 +000034 * @author $Id: 79cfc45d97b037436d50bda26111109bd5d42a37 $
Richard S. Hall2532cf82010-03-24 09:51:11 +000035 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +000036@ConsumerType
Richard S. Halldfd78a42012-05-11 20:19:02 +000037public abstract class AbstractURLStreamHandlerService extends URLStreamHandler implements URLStreamHandlerService {
Richard S. Hall2532cf82010-03-24 09:51:11 +000038 /**
39 * @see "java.net.URLStreamHandler.openConnection"
40 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +000041 @Override
Richard S. Halldfd78a42012-05-11 20:19:02 +000042 public abstract URLConnection openConnection(URL u) throws java.io.IOException;
Richard S. Hall2532cf82010-03-24 09:51:11 +000043
44 /**
Richard S. Halldfd78a42012-05-11 20:19:02 +000045 * The {@code URLStreamHandlerSetter} object passed to the parseURL method.
Richard S. Hall2532cf82010-03-24 09:51:11 +000046 */
47 protected volatile URLStreamHandlerSetter realHandler;
48
49 /**
Richard S. Halldfd78a42012-05-11 20:19:02 +000050 * Parse a URL using the {@code URLStreamHandlerSetter} object. This method
51 * sets the {@code realHandler} field with the specified
Richard S. Halld0dca9b2011-05-18 14:52:16 +000052 * {@code URLStreamHandlerSetter} object and then calls
53 * {@code parseURL(URL,String,int,int)}.
Richard S. Hall2532cf82010-03-24 09:51:11 +000054 *
Richard S. Halldfd78a42012-05-11 20:19:02 +000055 * @param realHandler The object on which the {@code setURL} method must be
56 * invoked for the specified URL.
Richard S. Hall2532cf82010-03-24 09:51:11 +000057 * @see "java.net.URLStreamHandler.parseURL"
58 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +000059 public void parseURL(@SuppressWarnings("hiding") URLStreamHandlerSetter realHandler, URL u, String spec, int start, int limit) {
Richard S. Hall2532cf82010-03-24 09:51:11 +000060 this.realHandler = realHandler;
61 parseURL(u, spec, start, limit);
62 }
63
64 /**
Richard S. Halld0dca9b2011-05-18 14:52:16 +000065 * This method calls {@code super.toExternalForm}.
Richard S. Hall2532cf82010-03-24 09:51:11 +000066 *
67 * @see "java.net.URLStreamHandler.toExternalForm"
68 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +000069 @Override
Richard S. Hall2532cf82010-03-24 09:51:11 +000070 public String toExternalForm(URL u) {
71 return super.toExternalForm(u);
72 }
73
74 /**
Richard S. Halld0dca9b2011-05-18 14:52:16 +000075 * This method calls {@code super.equals(URL,URL)}.
Richard S. Hall2532cf82010-03-24 09:51:11 +000076 *
77 * @see "java.net.URLStreamHandler.equals(URL,URL)"
78 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +000079 @Override
Richard S. Hall2532cf82010-03-24 09:51:11 +000080 public boolean equals(URL u1, URL u2) {
81 return super.equals(u1, u2);
82 }
83
84 /**
Richard S. Halld0dca9b2011-05-18 14:52:16 +000085 * This method calls {@code super.getDefaultPort}.
Richard S. Hall2532cf82010-03-24 09:51:11 +000086 *
87 * @see "java.net.URLStreamHandler.getDefaultPort"
88 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +000089 @Override
Richard S. Hall2532cf82010-03-24 09:51:11 +000090 public int getDefaultPort() {
91 return super.getDefaultPort();
92 }
93
94 /**
Richard S. Halld0dca9b2011-05-18 14:52:16 +000095 * This method calls {@code super.getHostAddress}.
Richard S. Hall2532cf82010-03-24 09:51:11 +000096 *
97 * @see "java.net.URLStreamHandler.getHostAddress"
98 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +000099 @Override
Richard S. Hall2532cf82010-03-24 09:51:11 +0000100 public InetAddress getHostAddress(URL u) {
101 return super.getHostAddress(u);
102 }
103
104 /**
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000105 * This method calls {@code super.hashCode(URL)}.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000106 *
107 * @see "java.net.URLStreamHandler.hashCode(URL)"
108 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000109 @Override
Richard S. Hall2532cf82010-03-24 09:51:11 +0000110 public int hashCode(URL u) {
111 return super.hashCode(u);
112 }
113
114 /**
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000115 * This method calls {@code super.hostsEqual}.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000116 *
117 * @see "java.net.URLStreamHandler.hostsEqual"
118 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000119 @Override
Richard S. Hall2532cf82010-03-24 09:51:11 +0000120 public boolean hostsEqual(URL u1, URL u2) {
121 return super.hostsEqual(u1, u2);
122 }
123
124 /**
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000125 * This method calls {@code super.sameFile}.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000126 *
127 * @see "java.net.URLStreamHandler.sameFile"
128 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000129 @Override
Richard S. Hall2532cf82010-03-24 09:51:11 +0000130 public boolean sameFile(URL u1, URL u2) {
131 return super.sameFile(u1, u2);
132 }
133
134 /**
135 * This method calls
Richard S. Halld0dca9b2011-05-18 14:52:16 +0000136 * {@code realHandler.setURL(URL,String,String,int,String,String)}.
Richard S. Hall2532cf82010-03-24 09:51:11 +0000137 *
138 * @see "java.net.URLStreamHandler.setURL(URL,String,String,int,String,String)"
139 * @deprecated This method is only for compatibility with handlers written
140 * for JDK 1.1.
141 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000142 @SuppressWarnings("javadoc")
Richard S. Halldfd78a42012-05-11 20:19:02 +0000143 protected void setURL(URL u, String proto, String host, int port, String file, String ref) {
Richard S. Hall2532cf82010-03-24 09:51:11 +0000144 realHandler.setURL(u, proto, host, port, file, ref);
145 }
146
147 /**
148 * This method calls
Richard S. Halldfd78a42012-05-11 20:19:02 +0000149 * {@code realHandler.setURL(URL,String,String,int,String,String,String,String)}
150 * .
Richard S. Hall2532cf82010-03-24 09:51:11 +0000151 *
152 * @see "java.net.URLStreamHandler.setURL(URL,String,String,int,String,String,String,String)"
153 */
Carsten Ziegeler3314f912014-07-30 07:22:32 +0000154 @Override
Richard S. Halldfd78a42012-05-11 20:19:02 +0000155 protected void setURL(URL u, String proto, String host, int port, String auth, String user, String path, String query, String ref) {
Richard S. Hall2532cf82010-03-24 09:51:11 +0000156 realHandler.setURL(u, proto, host, port, auth, user, path, query, ref);
157 }
158}