1 17 18 package org.apache.geronimo.system.url; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.io.OutputStream ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.net.URLConnection ; 26 import java.security.Permission ; 27 import java.util.Map ; 28 29 34 public class DelegatingURLConnection extends URLConnection { 35 private URL delegateUrl; 36 private URLConnection delegateConnection; 37 38 public DelegatingURLConnection(final URL url) throws MalformedURLException , IOException { 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 makeDelegateUrl(final URL url) throws MalformedURLException , IOException { 49 assert url != null; 50 51 return url; 52 } 53 54 private URLConnection makeDelegateUrlConnection(final URL url) throws IOException { 55 assert url != null; 56 57 return url.openConnection(); 58 } 59 60 public void connect() throws IOException { 61 delegateConnection.connect(); 62 } 63 64 public URL getURL() { 65 return delegateConnection.getURL(); 66 } 67 68 public int getContentLength() { 69 return delegateConnection.getContentLength(); 70 } 71 72 public String getContentType() { 73 return delegateConnection.getContentType(); 74 } 75 76 public String 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 getHeaderField(String name) { 93 return delegateConnection.getHeaderField(name); 94 } 95 96 public Map getHeaderFields() { 97 return delegateConnection.getHeaderFields(); 98 } 99 100 public int getHeaderFieldInt(String name, int _default) { 101 return delegateConnection.getHeaderFieldInt(name, _default); 102 } 103 104 public long getHeaderFieldDate(String name, long _default) { 105 return delegateConnection.getHeaderFieldDate(name, _default); 106 } 107 108 public String getHeaderFieldKey(int n) { 109 return delegateConnection.getHeaderFieldKey(n); 110 } 111 112 public String getHeaderField(int n) { 113 return delegateConnection.getHeaderField(n); 114 } 115 116 public Object getContent() throws IOException { 117 return delegateConnection.getContent(); 118 } 119 120 public Object getContent(Class [] classes) throws IOException { 121 return delegateConnection.getContent(classes); 122 } 123 124 public Permission getPermission() throws IOException { 125 return delegateConnection.getPermission(); 126 } 127 128 public InputStream getInputStream() throws IOException { 129 return delegateConnection.getInputStream(); 130 } 131 132 public OutputStream getOutputStream() throws IOException { 133 return delegateConnection.getOutputStream(); 134 } 135 136 public String 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 key, String value) { 189 delegateConnection.setRequestProperty(key, value); 190 } 191 192 public void addRequestProperty(String key, String value) { 193 delegateConnection.addRequestProperty(key, value); 194 } 195 196 public String getRequestProperty(String key) { 197 return delegateConnection.getRequestProperty(key); 198 } 199 200 public Map getRequestProperties() { 201 return delegateConnection.getRequestProperties(); 202 } 203 } 204 | Popular Tags |