01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
18:
19: import java.util.Collections;
20: import java.util.Enumeration;
21: import java.util.List;
22:
23: import javax.servlet.http.HttpSession;
24:
25: import org.apache.tapestry.ioc.internal.util.InternalUtils;
26: import org.apache.tapestry.services.Session;
27:
28: /**
29: * A thin wrapper around {@link HttpSession}.
30: */
31: public class SessionImpl implements Session {
32: private final HttpSession _session;
33:
34: public SessionImpl(HttpSession session) {
35: _session = session;
36: }
37:
38: public Object getAttribute(String name) {
39: return _session.getAttribute(name);
40: }
41:
42: public List<String> getAttributeNames() {
43: return InternalUtils.toList(_session.getAttributeNames());
44: }
45:
46: public void setAttribute(String name, Object value) {
47: _session.setAttribute(name, value);
48: }
49:
50: public List<String> getAttributeNames(String prefix) {
51: List<String> result = newList();
52:
53: Enumeration e = _session.getAttributeNames();
54: while (e.hasMoreElements()) {
55: String name = (String) e.nextElement();
56:
57: if (name.startsWith(prefix))
58: result.add(name);
59: }
60:
61: Collections.sort(result);
62:
63: return result;
64: }
65:
66: public int getMaxInactiveInterval() {
67: return _session.getMaxInactiveInterval();
68: }
69:
70: public void invalidate() {
71: _session.invalidate();
72: }
73:
74: public void setMaxInactiveInterval(int seconds) {
75: _session.setMaxInactiveInterval(seconds);
76: }
77:
78: }
|