KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > protocol > DelegatingURLConnection


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.net.protocol;
23
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27
28 import java.net.URLConnection JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.net.MalformedURLException JavaDoc;
31
32 import java.security.Permission JavaDoc;
33
34 /**
35  * An delegating URLConnection support class.
36  *
37  * @todo resolve 1.4 specific issues.
38  *
39  * @version <tt>$Revision: 1958 $</tt>
40  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
41  */

42 public class DelegatingURLConnection
43    extends URLConnection JavaDoc
44 {
45    protected URL JavaDoc delegateUrl;
46    protected URLConnection JavaDoc delegateConnection;
47
48    public DelegatingURLConnection(final URL JavaDoc url)
49       throws MalformedURLException JavaDoc, IOException JavaDoc
50    {
51       super(url);
52       
53       delegateUrl = makeDelegateUrl(url);
54       delegateConnection = makeDelegateUrlConnection(delegateUrl);
55    }
56
57    protected URL JavaDoc makeDelegateUrl(final URL JavaDoc url)
58       throws MalformedURLException JavaDoc, IOException JavaDoc
59    {
60       return url;
61    }
62
63    protected URLConnection JavaDoc makeDelegateUrlConnection(final URL JavaDoc url)
64       throws IOException JavaDoc
65    {
66       return url.openConnection();
67    }
68
69    public void connect() throws IOException JavaDoc
70    {
71       delegateConnection.connect();
72    }
73    
74    public URL JavaDoc getURL() {
75       return delegateConnection.getURL();
76    }
77
78    public int getContentLength() {
79       return delegateConnection.getContentLength();
80    }
81
82    public String JavaDoc getContentType() {
83       return delegateConnection.getContentType();
84    }
85
86    public String JavaDoc getContentEncoding() {
87       return delegateConnection.getContentEncoding();
88    }
89
90    public long getExpiration() {
91       return delegateConnection.getExpiration();
92    }
93
94    public long getDate() {
95       return delegateConnection.getDate();
96    }
97
98    public long getLastModified() {
99       return delegateConnection.getLastModified();
100    }
101
102    public String JavaDoc getHeaderField(String JavaDoc name) {
103       return delegateConnection.getHeaderField(name);
104    }
105
106    /* This is specific to 1.4
107    public Map getHeaderFields() {
108       return delegateConnection.getHeaderFields();
109    }
110    */

111    
112    public int getHeaderFieldInt(String JavaDoc name, int _default) {
113       return delegateConnection.getHeaderFieldInt(name, _default);
114    }
115
116    public long getHeaderFieldDate(String JavaDoc name, long _default) {
117       return delegateConnection.getHeaderFieldDate(name, _default);
118    }
119
120    public String JavaDoc getHeaderFieldKey(int n) {
121       return delegateConnection.getHeaderFieldKey(n);
122    }
123
124    public String JavaDoc getHeaderField(int n) {
125       return delegateConnection.getHeaderField(n);
126    }
127
128    public Object JavaDoc getContent() throws IOException JavaDoc {
129       return delegateConnection.getContent();
130    }
131
132    public Object JavaDoc getContent(Class JavaDoc[] classes) throws IOException JavaDoc {
133       return delegateConnection.getContent(classes);
134    }
135
136    public Permission JavaDoc getPermission() throws IOException JavaDoc {
137       return delegateConnection.getPermission();
138    }
139
140    public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
141       return delegateConnection.getInputStream();
142    }
143
144    public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
145       return delegateConnection.getOutputStream();
146    }
147
148    public String JavaDoc toString() {
149       return super.toString() + "{ " + delegateConnection + " }";
150    }
151
152    public void setDoInput(boolean doinput) {
153       delegateConnection.setDoInput(doinput);
154    }
155    
156    public boolean getDoInput() {
157       return delegateConnection.getDoInput();
158    }
159
160    public void setDoOutput(boolean dooutput) {
161       delegateConnection.setDoOutput(dooutput);
162     }
163
164    public boolean getDoOutput() {
165       return delegateConnection.getDoOutput();
166    }
167
168    public void setAllowUserInteraction(boolean allowuserinteraction) {
169       delegateConnection.setAllowUserInteraction(allowuserinteraction);
170    }
171
172    public boolean getAllowUserInteraction() {
173       return delegateConnection.getAllowUserInteraction();
174    }
175
176    public void setUseCaches(boolean usecaches) {
177       delegateConnection.setUseCaches(usecaches);
178    }
179
180    public boolean getUseCaches() {
181       return delegateConnection.getUseCaches();
182    }
183
184    public void setIfModifiedSince(long ifmodifiedsince) {
185       delegateConnection.setIfModifiedSince(ifmodifiedsince);
186    }
187
188    public long getIfModifiedSince() {
189       return delegateConnection.getIfModifiedSince();
190    }
191
192    public boolean getDefaultUseCaches() {
193       return delegateConnection.getDefaultUseCaches();
194    }
195
196    public void setDefaultUseCaches(boolean defaultusecaches) {
197       delegateConnection.setDefaultUseCaches(defaultusecaches);
198    }
199
200    public void setRequestProperty(String JavaDoc key, String JavaDoc value) {
201       delegateConnection.setRequestProperty(key, value);
202    }
203
204    /* This is specific to 1.4
205    public void addRequestProperty(String key, String value) {
206       delegateConnection.addRequestProperty(key, value);
207    }
208    */

209    
210    public String JavaDoc getRequestProperty(String JavaDoc key) {
211       return delegateConnection.getRequestProperty(key);
212    }
213
214    /* This is specific to 1.4
215    public Map getRequestProperties() {
216       return delegateConnection.getRequestProperties();
217    }
218    */

219 }
220
Popular Tags