1 14 package org.wings.externalizer; 15 16 import java.util.Collection ; 17 18 22 public class ExternalizedResource { 23 27 private final Object extObject; 28 private final Externalizer externalizer; 29 30 private final String mimeType; 31 private final int flags; 32 private final long lastModified; 33 private final Collection headers; 34 private String id; 35 36 public ExternalizedResource(Object obj, Externalizer ext, 37 String mimeType, Collection headers, int flags) { 38 extObject = obj; 39 externalizer = ext; 40 this.mimeType = mimeType; 41 this.flags = flags; 42 43 if (externalizer == null || extObject == null) { 44 throw new IllegalArgumentException ("no externalizer or null object"); 45 } 46 47 lastModified = System.currentTimeMillis(); 48 this.headers = headers; 49 } 50 51 52 public final String getMimeType() { 53 return mimeType == null ? externalizer.getMimeType(extObject) : mimeType; 54 } 55 56 57 public final Object getObject() { 58 return extObject; 59 } 60 61 62 public final Externalizer getExternalizer() { 63 return externalizer; 64 } 65 66 67 public final Collection getHeaders() { 68 return headers == null ? externalizer.getHeaders(extObject) : headers; 69 } 70 71 72 public final boolean deliverOnce() { 73 return (flags & AbstractExternalizeManager.REQUEST) > 0; 74 } 75 76 77 public final boolean isFinal() { 78 return (((flags & AbstractExternalizeManager.FINAL) > 0 79 || externalizer.isFinal(extObject)) 80 && (flags & AbstractExternalizeManager.REQUEST) == 0); 82 } 83 84 85 public final String getExtension() { 86 return externalizer.getExtension(extObject); 87 } 88 89 90 public final int getFlags() { 91 return flags; 92 } 93 94 95 public final long getLastModified() { 96 if (isFinal()) 97 return lastModified; 98 else 99 return -1; 100 } 101 102 103 void setId(String s) { 104 id = s; 105 } 106 107 108 public String getId() { 109 return id; 110 } 111 112 113 public String toString() { 114 return "Externalized Info"; 115 } 116 117 126 public final int hashCode() { 127 return extObject.hashCode(); 128 } 129 130 138 public final boolean equals(ExternalizedResource e) { 139 return (extObject.equals(e.extObject) 140 && externalizer.equals(e.externalizer)); 141 } 142 143 147 public final boolean equals(Object o) { 148 if (o instanceof ExternalizedResource) { 149 return equals((ExternalizedResource) o); 150 } 151 return false; 152 } 153 154 } 155 156 157 158 159 160 161 | Popular Tags |