01: // CachedResourceFactory.java
02: // $Id: CachedResourceFactory.java,v 1.16 2000/08/16 21:38:04 ylafon Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 1999.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.www.protocol.http.cache;
07:
08: import java.io.IOException;
09:
10: import org.w3c.www.protocol.http.Reply;
11: import org.w3c.www.protocol.http.Request;
12:
13: /**
14: * The factory for cache entries.
15: * All cache entries have to be sub-classes of CachedResource, that's the
16: * only limitation to the fun you can have down here.
17: */
18: public class CachedResourceFactory {
19: /**
20: * Create a suitable instance of some subclass of CachedResource.
21: * @param filter The cache filter that ones to create a new entry.
22: * @param request The original request we emitted.
23: * @param reply The reply we got from the origin server.
24: * @return An instance of CachedResource, or <strong>null</strong>
25: * if no resource was created.
26: */
27: public static CachedResource createResource(CacheFilter filter,
28: Request request, Reply reply) throws IOException {
29: CachedResource r = null;
30: String v[] = reply.getVary();
31:
32: // this is a nightmare, as there is no capitalization
33: // and someone may add other headers
34: // on top of that Apache use Vary: negotiate every time the
35: // Content-Location is not the same as the request URI...
36:
37: if (v == null) {
38: // no vary, the easy way :)
39: r = new EntityCachedResource(filter, request, reply);
40: } else {
41: // Check for a varying resource first:
42: // if ( reply.hasHeader(reply.H_VARY) )
43: // r = new VaryResource(filter, request, reply);
44: // else
45: r = new EntityCachedResource(filter, request, reply);
46: }
47: return r;
48: }
49: }
|