KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > commandline > CommandLineSession


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.environment.commandline;
17
18 import org.apache.cocoon.environment.Session;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.Hashtable JavaDoc;
22
23 /**
24  *
25  * Command-line version of Http Session.
26  *
27  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
28  * @version CVS $Id: CommandLineSession.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public final class CommandLineSession
31 implements Session {
32
33     private long creationTime = System.currentTimeMillis();
34
35     private Hashtable JavaDoc attributes = new Hashtable JavaDoc();
36
37     public CommandLineSession() {
38     }
39
40     public long getCreationTime() {
41         return this.creationTime;
42     }
43
44     public String JavaDoc getId() {
45         return "1";
46     }
47
48     public long getLastAccessedTime() {
49         return this.creationTime;
50     }
51
52     public void setMaxInactiveInterval(int interval) {
53         // ignored
54
}
55
56     public int getMaxInactiveInterval() {
57         return -1;
58     }
59
60     public Object JavaDoc getAttribute(String JavaDoc name) {
61         return this.attributes.get(name);
62     }
63
64     public Enumeration JavaDoc getAttributeNames() {
65         return this.attributes.keys();
66     }
67
68     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
69         this.attributes.put(name, value);
70     }
71
72     public void removeAttribute(String JavaDoc name) {
73         this.attributes.remove(name);
74     }
75
76     public void invalidate() {
77         this.attributes.clear();
78         invalidateSession();
79     }
80
81     public boolean isNew() {
82         return false;
83     }
84
85     protected static CommandLineSession session;
86
87     /**
88      * Get the current session object - if available
89      */

90     public static Session getSession(boolean create) {
91         if (create && session == null) {
92             session = new CommandLineSession();
93         }
94         return session;
95     }
96
97     /**
98      * Invalidate the current session
99      */

100     public static void invalidateSession() {
101         session = null;
102     }
103
104 }
105
106
Popular Tags