1 14 package org.wings; 15 16 import org.wings.session.Session; 17 import org.wings.session.SessionManager; 18 19 import java.io.Serializable ; 20 import java.util.Collection ; 21 import java.util.Map ; 22 23 31 32 37 public abstract class Resource implements Serializable , URLResource, Renderable { 38 private final transient static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("org.wings"); 39 40 41 protected String id; 42 43 protected String extension; 44 45 protected String mimeType; 46 47 protected Collection headers; 48 49 protected Resource(String extension, String mimeType) { 50 this.extension = extension; 51 this.mimeType = mimeType; 52 } 53 54 protected Resource() { 55 } 56 57 58 public int getLength() { 59 return -1; 60 } 61 62 63 public String getExtension() { 64 return extension; 65 } 66 67 70 public String getMimeType() { 71 return mimeType; 72 } 73 74 public void setHeaders(Collection headers) { 75 this.headers = headers; 76 } 77 78 public Collection getHeaders() { 79 return headers; 80 } 81 82 83 public String getId() { 84 return id; 85 } 86 87 public abstract SimpleURL getURL(); 88 89 90 public String toString() { 91 return getId(); 92 } 93 94 public Session getSession() { 95 return SessionManager.getSession(); 96 } 97 98 public static final class HeaderEntry implements Map.Entry { 99 final Object key; 100 Object value; 101 102 105 public HeaderEntry(Object k, Object v) { 106 key = k; 107 value = v; 108 } 109 110 public Object getKey() { 111 return key; 112 } 113 114 public Object getValue() { 115 return value; 116 } 117 118 public Object setValue(Object newValue) { 119 Object oldValue = value; 120 value = newValue; 121 return oldValue; 122 } 123 124 public boolean equals(Object o) { 125 if (!(o instanceof Map.Entry )) 126 return false; 127 Map.Entry e = (Map.Entry ) o; 128 Object k1 = getKey(); 129 Object k2 = e.getKey(); 130 if (k1 == k2 || (k1 != null && k1.equals(k2))) { 131 Object v1 = getValue(); 132 Object v2 = e.getValue(); 133 if (v1 == v2 || (v1 != null && v1.equals(v2))) 134 return true; 135 } 136 return false; 137 } 138 139 public int hashCode() { 140 return (key == null ? 0 : key.hashCode()) ^ 141 (value == null ? 0 : value.hashCode()); 142 } 143 144 public String toString() { 145 return getKey() + "=" + getValue(); 146 } 147 148 } 149 150 } 151 152 153 | Popular Tags |