KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > url > DelegatingURLConnection


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.system.url;
19
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.net.URLConnection JavaDoc;
26 import java.security.Permission JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * An delegating URLConnection support class.
31  *
32  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
33  */

34 public class DelegatingURLConnection extends URLConnection JavaDoc {
35     private URL JavaDoc delegateUrl;
36     private URLConnection JavaDoc delegateConnection;
37
38     public DelegatingURLConnection(final URL JavaDoc url) throws MalformedURLException JavaDoc, IOException JavaDoc {
39         super(url);
40
41         delegateUrl = makeDelegateUrl(url);
42         assert delegateUrl != null;
43
44         delegateConnection = makeDelegateUrlConnection(delegateUrl);
45         assert delegateConnection != null;
46     }
47
48     protected URL JavaDoc makeDelegateUrl(final URL JavaDoc url) throws MalformedURLException JavaDoc, IOException JavaDoc {
49         assert url != null;
50
51         return url;
52     }
53
54     private URLConnection JavaDoc makeDelegateUrlConnection(final URL JavaDoc url) throws IOException JavaDoc {
55         assert url != null;
56
57         return url.openConnection();
58     }
59
60     public void connect() throws IOException JavaDoc {
61         delegateConnection.connect();
62     }
63
64     public URL JavaDoc getURL() {
65         return delegateConnection.getURL();
66     }
67
68     public int getContentLength() {
69         return delegateConnection.getContentLength();
70     }
71
72     public String JavaDoc getContentType() {
73         return delegateConnection.getContentType();
74     }
75
76     public String JavaDoc getContentEncoding() {
77         return delegateConnection.getContentEncoding();
78     }
79
80     public long getExpiration() {
81         return delegateConnection.getExpiration();
82     }
83
84     public long getDate() {
85         return delegateConnection.getDate();
86     }
87
88     public long getLastModified() {
89         return delegateConnection.getLastModified();
90     }
91
92     public String JavaDoc getHeaderField(String JavaDoc name) {
93         return delegateConnection.getHeaderField(name);
94     }
95
96     public Map JavaDoc getHeaderFields() {
97         return delegateConnection.getHeaderFields();
98     }
99
100     public int getHeaderFieldInt(String JavaDoc name, int _default) {
101         return delegateConnection.getHeaderFieldInt(name, _default);
102     }
103
104     public long getHeaderFieldDate(String JavaDoc name, long _default) {
105         return delegateConnection.getHeaderFieldDate(name, _default);
106     }
107
108     public String JavaDoc getHeaderFieldKey(int n) {
109         return delegateConnection.getHeaderFieldKey(n);
110     }
111
112     public String JavaDoc getHeaderField(int n) {
113         return delegateConnection.getHeaderField(n);
114     }
115
116     public Object JavaDoc getContent() throws IOException JavaDoc {
117         return delegateConnection.getContent();
118     }
119
120     public Object JavaDoc getContent(Class JavaDoc[] classes) throws IOException JavaDoc {
121         return delegateConnection.getContent(classes);
122     }
123
124     public Permission JavaDoc getPermission() throws IOException JavaDoc {
125         return delegateConnection.getPermission();
126     }
127
128     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
129         return delegateConnection.getInputStream();
130     }
131
132     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
133         return delegateConnection.getOutputStream();
134     }
135
136     public String JavaDoc toString() {
137         return super.toString() + "{ " + delegateConnection + " }";
138     }
139
140     public void setDoInput(boolean doinput) {
141         delegateConnection.setDoInput(doinput);
142     }
143
144     public boolean getDoInput() {
145         return delegateConnection.getDoInput();
146     }
147
148     public void setDoOutput(boolean dooutput) {
149         delegateConnection.setDoOutput(dooutput);
150     }
151
152     public boolean getDoOutput() {
153         return delegateConnection.getDoOutput();
154     }
155
156     public void setAllowUserInteraction(boolean allowuserinteraction) {
157         delegateConnection.setAllowUserInteraction(allowuserinteraction);
158     }
159
160     public boolean getAllowUserInteraction() {
161         return delegateConnection.getAllowUserInteraction();
162     }
163
164     public void setUseCaches(boolean usecaches) {
165         delegateConnection.setUseCaches(usecaches);
166     }
167
168     public boolean getUseCaches() {
169         return delegateConnection.getUseCaches();
170     }
171
172     public void setIfModifiedSince(long ifmodifiedsince) {
173         delegateConnection.setIfModifiedSince(ifmodifiedsince);
174     }
175
176     public long getIfModifiedSince() {
177         return delegateConnection.getIfModifiedSince();
178     }
179
180     public boolean getDefaultUseCaches() {
181         return delegateConnection.getDefaultUseCaches();
182     }
183
184     public void setDefaultUseCaches(boolean defaultusecaches) {
185         delegateConnection.setDefaultUseCaches(defaultusecaches);
186     }
187
188     public void setRequestProperty(String JavaDoc key, String JavaDoc value) {
189         delegateConnection.setRequestProperty(key, value);
190     }
191
192     public void addRequestProperty(String JavaDoc key, String JavaDoc value) {
193         delegateConnection.addRequestProperty(key, value);
194     }
195
196     public String JavaDoc getRequestProperty(String JavaDoc key) {
197         return delegateConnection.getRequestProperty(key);
198     }
199
200     public Map JavaDoc getRequestProperties() {
201         return delegateConnection.getRequestProperties();
202     }
203 }
204
Popular Tags