KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderDATA


1 /******************************************************************************
2  * ResponderDATA.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.servlets.responders;
11
12 import java.io.*;
13 import java.util.Properties JavaDoc;
14 import javax.servlet.ServletConfig JavaDoc;
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
18 import javax.servlet.ServletOutputStream JavaDoc;
19 import org.openlaszlo.cache.DataCache;
20 import org.openlaszlo.cache.RequestCache;
21 import org.openlaszlo.server.LPS;
22
23 import org.apache.log4j.Logger;
24
25 /**
26  *
27  */

28 public final class ResponderDATA extends ResponderCache
29 {
30     private static DataCache mCache = null;
31     private static boolean mIsInitialized = false;
32     private static Logger mLogger = Logger.getLogger(ResponderDATA.class);
33
34     synchronized public void init(String JavaDoc reqName, ServletConfig JavaDoc config, Properties JavaDoc prop)
35         throws ServletException JavaDoc, IOException
36     {
37         // Cache should only be initialized once.
38
if (! mIsInitialized) {
39             // Initialize data cache
40
String JavaDoc cacheDir = config.getInitParameter("lps.dcache.directory");
41             if (cacheDir == null) {
42                 cacheDir = prop.getProperty("dcache.directory");
43             }
44             if (cacheDir == null) {
45                 cacheDir = LPS.getWorkDirectory() + File.separator + "dcache";
46             }
47
48             File cache = checkDirectory(cacheDir);
49             mLogger.info("Data Cache is at " + cacheDir);
50
51             //------------------------------------------------------------
52
// Support for new style data response
53
//------------------------------------------------------------
54
try {
55                 mCache = new DataCache(cache, prop);
56             } catch (IOException e) {
57                 throw new ServletException JavaDoc(e.getMessage());
58             }
59
60             mIsInitialized = true;
61         }
62         super.init(reqName, config, mCache, prop);
63     }
64
65     static public RequestCache getCache() {
66         return mCache;
67     }
68 }
69
Popular Tags