KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tester > SessionBean


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;
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  *
32  * @author Craig R. McClanahan
33  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:57 $
34  */

35
36 public class SessionBean implements
37     HttpSessionActivationListener JavaDoc, HttpSessionBindingListener JavaDoc, Serializable JavaDoc {
38
39
40     // ------------------------------------------------------------- Properties
41

42
43     /**
44      * A date property for use with property editor tests.
45      */

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

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

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

88
89     /**
90      * Return a string representation of this bean.
91      */

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

108
109     /**
110      * Receive notification that this session was activated.
111      *
112      * @param event The session event that has occurred
113      */

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

126     public void sessionWillPassivate(HttpSessionEvent JavaDoc event) {
127
128         lifecycle += "/swp";
129
130     }
131
132
133     // ------------------------------------- HttpSessionBindingListener Methods
134

135
136     /**
137      * Receive notification that this attribute has been bound.
138      *
139      * @param event The session event that has occurred
140      */

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

153     public void valueUnbound(HttpSessionBindingEvent JavaDoc event) {
154
155         lifecycle += "/vu";
156
157     }
158
159
160 }
161
162
Popular Tags