KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > env > SessionCallback


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.env;
31
32 import com.caucho.quercus.QuercusRuntimeException;
33
34 import java.util.logging.Level JavaDoc;
35 import java.util.logging.Logger JavaDoc;
36
37 /**
38  * Represents a PHP session callback.
39  */

40 public class SessionCallback extends Value {
41   private static final Logger JavaDoc log
42     = Logger.getLogger(SessionCallback.class.getName());
43
44   private Callback _open;
45   private Callback _close;
46   private Callback _read;
47   private Callback _write;
48   private Callback _destroy;
49   private Callback _gc;
50
51   public SessionCallback(Callback open,
52                          Callback close,
53                          Callback read,
54                          Callback write,
55                          Callback destroy,
56                          Callback gc)
57   {
58     _open = open;
59     _close = close;
60     _read = read;
61     _write = write;
62     _destroy = destroy;
63     _gc = gc;
64   }
65
66   public void open(Env env, String JavaDoc savePath, String JavaDoc sessionName)
67   {
68     _open.call(env, new StringValueImpl(savePath), new StringValueImpl(sessionName));
69   }
70
71   public StringValue read(Env env, String JavaDoc id)
72   {
73     try {
74       Value value = _read.call(env, new StringValueImpl(id));
75
76       if (value instanceof StringValue)
77         return (StringValue) value;
78       else
79         return null;
80     } catch (RuntimeException JavaDoc e) {
81       throw e;
82     } catch (Throwable JavaDoc e) {
83       throw new QuercusRuntimeException(e);
84     }
85   }
86
87   public void write(Env env, String JavaDoc id, String JavaDoc value)
88   {
89     try {
90       _write.call(env, new StringValueImpl(id), new StringValueImpl(value));
91     } catch (RuntimeException JavaDoc e) {
92       throw e;
93     } catch (Throwable JavaDoc e) {
94       log.log(Level.FINE, e.toString(), e);
95     }
96   }
97
98   public void destroy(Env env, String JavaDoc id)
99   {
100     try {
101       _destroy.call(env, new StringValueImpl(id));
102     } catch (RuntimeException JavaDoc e) {
103       throw e;
104     } catch (Throwable JavaDoc e) {
105       log.log(Level.FINE, e.toString(), e);
106     }
107   }
108
109   public void close(Env env)
110   {
111     try {
112       _close.call(env);
113     } catch (RuntimeException JavaDoc e) {
114       throw e;
115     } catch (Throwable JavaDoc e) {
116       log.log(Level.FINE, e.toString(), e);
117     }
118   }
119 }
120
Popular Tags