KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tester > shared > SharedSessionBean


1 /*
2  * Copyright 1999, 2000 ,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.tester.shared;
18
19
20 import java.io.Serializable JavaDoc;
21 import java.sql.Date JavaDoc;
22 import javax.servlet.http.HttpSessionActivationListener JavaDoc;
23 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
24 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
25 import javax.servlet.http.HttpSessionEvent JavaDoc;
26
27
28 /**
29  * Simple JavaBean to use for session attribute tests. It is Serializable
30  * so that instances can be saved and restored across server restarts.
31  * <p>
32  * This is functionally equivalent to <code>SessionBean</code>, but stored
33  * in a different package so that it gets deployed into a JAR file under
34  * <code>$CATALINA_HOME/lib</code>.
35  *
36  * @author Craig R. McClanahan
37  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:59:01 $
38  */

39
40 public class SharedSessionBean implements
41     HttpSessionActivationListener JavaDoc, HttpSessionBindingListener JavaDoc, Serializable JavaDoc {
42
43
44     // ------------------------------------------------------------- Properties
45

46
47     /**
48      * A date property for use with property editor tests.
49      */

50     protected Date JavaDoc dateProperty =
51         new Date JavaDoc(System.currentTimeMillis());
52
53     public Date JavaDoc getDateProperty() {
54         return (this.dateProperty);
55     }
56
57     public void setDateProperty(Date JavaDoc dateProperty) {
58         this.dateProperty = dateProperty;
59     }
60
61
62     /**
63      * The lifecycle events that have happened on this bean instance.
64      */

65     protected String JavaDoc lifecycle = "";
66
67     public String JavaDoc getLifecycle() {
68         return (this.lifecycle);
69     }
70
71     public void setLifecycle(String JavaDoc lifecycle) {
72         this.lifecycle = lifecycle;
73     }
74
75
76     /**
77      * A string property.
78      */

79     protected String JavaDoc stringProperty = "Default String Property Value";
80
81     public String JavaDoc getStringProperty() {
82         return (this.stringProperty);
83     }
84
85     public void setStringProperty(String JavaDoc stringProperty) {
86         this.stringProperty = stringProperty;
87     }
88
89
90     // --------------------------------------------------------- Public Methods
91

92
93     /**
94      * Return a string representation of this bean.
95      */

96     public String JavaDoc toString() {
97
98         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("SharedSessionBean[lifecycle=");
99         sb.append(this.lifecycle);
100         sb.append(",dateProperty=");
101         sb.append(dateProperty);
102         sb.append(",stringProperty=");
103         sb.append(this.stringProperty);
104         sb.append("]");
105         return (sb.toString());
106
107     }
108
109
110     // ---------------------------------- HttpSessionActivationListener Methods
111

112
113     /**
114      * Receive notification that this session was activated.
115      *
116      * @param event The session event that has occurred
117      */

118     public void sessionDidActivate(HttpSessionEvent JavaDoc event) {
119
120         lifecycle += "/sda";
121
122     }
123
124
125     /**
126      * Receive notification that this session will be passivated.
127      *
128      * @param event The session event that has occurred
129      */

130     public void sessionWillPassivate(HttpSessionEvent JavaDoc event) {
131
132         lifecycle += "/swp";
133
134     }
135
136
137     // ------------------------------------- HttpSessionBindingListener Methods
138

139
140     /**
141      * Receive notification that this attribute has been bound.
142      *
143      * @param event The session event that has occurred
144      */

145     public void valueBound(HttpSessionBindingEvent JavaDoc event) {
146
147         lifecycle += "/vb";
148
149     }
150
151
152     /**
153      * Receive notification that this attribute has been unbound.
154      *
155      * @param event The session event that has occurred
156      */

157     public void valueUnbound(HttpSessionBindingEvent JavaDoc event) {
158
159         lifecycle += "/vu";
160
161     }
162
163
164 }
165
166
Popular Tags