Java Source Code: org.jboss.net.protocol.DelegatingURLConnection


   1: /***************************************
   2:  *                                     *
   3:  *  JBoss: The OpenSource J2EE WebOS   *
   4:  *                                     *
   5:  *  Distributable under LGPL license.  *
   6:  *  See terms of license at gnu.org.   *
   7:  *                                     *
   8:  ***************************************/
   9: 
  10: package org.jboss.net.protocol;
  11: 
  12: import java.io.IOException;
  13: import java.io.InputStream;
  14: import java.io.OutputStream;
  15: 
  16: import java.net.URLConnection;
  17: import java.net.URL;
  18: import java.net.MalformedURLException;
  19: 
  20: import java.util.Map;
  21: 
  22: import java.security.Permission;
  23: 
  24: /**
  25:  * An delegating URLConnection support class.
  26:  *
  27:  * @todo resolve 1.4 specific issues.
  28:  *
  29:  * @version <tt>$Revision: 1.3 $</tt>
  30:  * @author  <a href="mailto:jason@planet57.com">Jason Dillon</a>
  31:  */
  32: public class DelegatingURLConnection
  33:    extends URLConnection
  34:	  {
  35:   protected URL delegateUrl;
  36:   protected URLConnection delegateConnection;
  37:
  38:   public DelegatingURLConnection(final URL url)
  39:      throws MalformedURLException, IOException
  40:	     {
  41:      super(url);
  42:      
  43:      delegateUrl = makeDelegateUrl(url);
  44:      delegateConnection = makeDelegateUrlConnection(delegateUrl);
  45:   }
  46:
  47:   protected URL makeDelegateUrl(final URL url)
  48:      throws MalformedURLException, IOException
  49:	     {
  50:      return url;
  51:   }
  52:
  53:   protected URLConnection makeDelegateUrlConnection(final URL url)
  54:      throws IOException
  55:	     {
  56:      return url.openConnection();
  57:   }
  58:
  59:   public void connect() throws IOException
  60:	     {
  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:   /* This is specific to 1.4
  97:	     public Map getHeaderFields() {
  98:      return delegateConnection.getHeaderFields();
  99:   }
 100:   */
 101:   
 102:	     public int getHeaderFieldInt(String name, int _default) {
 103:      return delegateConnection.getHeaderFieldInt(name, _default);
 104:   }
 105:
 106:	     public long getHeaderFieldDate(String name, long _default) {
 107:      return delegateConnection.getHeaderFieldDate(name, _default);
 108:   }
 109:
 110:	     public String getHeaderFieldKey(int n) {
 111:      return delegateConnection.getHeaderFieldKey(n);
 112:   }
 113:
 114:	     public String getHeaderField(int n) {
 115:      return delegateConnection.getHeaderField(n);
 116:   }
 117:
 118:	     public Object getContent() throws IOException {
 119:      return delegateConnection.getContent();
 120:   }
 121:
 122:	     public Object getContent(Class[] classes) throws IOException {
 123:      return delegateConnection.getContent(classes);
 124:   }
 125:
 126:	     public Permission getPermission() throws IOException {
 127:      return delegateConnection.getPermission();
 128:   }
 129:
 130:	     public InputStream getInputStream() throws IOException {
 131:      return delegateConnection.getInputStream();
 132:   }
 133:
 134:	     public OutputStream getOutputStream() throws IOException {
 135:      return delegateConnection.getOutputStream();
 136:   }
 137:
 138:	     public String toString() {
 139:      return super.toString() + "{ " + delegateConnection + " }";
 140:   }
 141:
 142:	     public void setDoInput(boolean doinput) {
 143:      delegateConnection.setDoInput(doinput);
 144:   }
 145:   
 146:	     public boolean getDoInput() {
 147:      return delegateConnection.getDoInput();
 148:   }
 149:
 150:	     public void setDoOutput(boolean dooutput) {
 151:      delegateConnection.setDoOutput(dooutput);
 152:    }
 153:
 154:	     public boolean getDoOutput() {
 155:      return delegateConnection.getDoOutput();
 156:   }
 157:
 158:	     public void setAllowUserInteraction(boolean allowuserinteraction) {
 159:      delegateConnection.setAllowUserInteraction(allowuserinteraction);
 160:   }
 161:
 162:	     public boolean getAllowUserInteraction() {
 163:      return delegateConnection.getAllowUserInteraction();
 164:   }
 165:
 166:	     public void setUseCaches(boolean usecaches) {
 167:      delegateConnection.setUseCaches(usecaches);
 168:   }
 169:
 170:	     public boolean getUseCaches() {
 171:      return delegateConnection.getUseCaches();
 172:   }
 173:
 174:	     public void setIfModifiedSince(long ifmodifiedsince) {
 175:      delegateConnection.setIfModifiedSince(ifmodifiedsince);
 176:   }
 177:
 178:	     public long getIfModifiedSince() {
 179:      return delegateConnection.getIfModifiedSince();
 180:   }
 181:
 182:	     public boolean getDefaultUseCaches() {
 183:      return delegateConnection.getDefaultUseCaches();
 184:   }
 185:
 186:	     public void setDefaultUseCaches(boolean defaultusecaches) {
 187:      delegateConnection.setDefaultUseCaches(defaultusecaches);
 188:   }
 189:
 190:	     public void setRequestProperty(String key, String value) {
 191:      delegateConnection.setRequestProperty(key, value);
 192:   }
 193:
 194:   /* This is specific to 1.4
 195:	     public void addRequestProperty(String key, String value) {
 196:      delegateConnection.addRequestProperty(key, value);
 197:   }
 198:   */
 199:   
 200:	     public String getRequestProperty(String key) {
 201:      return delegateConnection.getRequestProperty(key);
 202:   }
 203:
 204:   /* This is specific to 1.4
 205:	     public Map getRequestProperties() {
 206:      return delegateConnection.getRequestProperties();
 207:   }
 208:   */
 209:}