001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.pageflow.scoping.internal;
020:
021: import javax.servlet.http.HttpSession;
022: import javax.servlet.http.HttpSessionContext;
023: import javax.servlet.ServletContext;
024: import java.io.Serializable;
025:
026: /**
027: * A wrapper around HttpSession, associated with a given scope-key. All calls to setAttribute,
028: * getAttribute, removeAttribute, etc. are scoped to this object, while most other functionality
029: * delegates to the wrapped HttpSession.
030: */
031: public class ScopedSession extends ScopedAttributeContainer implements
032: HttpSession, Serializable {
033: private transient HttpSession _session;
034: private transient ServletContext _servletContext;
035:
036: /**
037: * This constructor exists only for deserialization.
038: */
039: public ScopedSession() {
040: super (null);
041: }
042:
043: public ScopedSession(HttpSession session, ServletContext cxt,
044: Object scopeKey) {
045: super (scopeKey);
046: _session = session;
047: _servletContext = cxt;
048: }
049:
050: public long getCreationTime() {
051: return _session.getCreationTime();
052: }
053:
054: public String getId() {
055: return getScopedName(_session.getId());
056: }
057:
058: public long getLastAccessedTime() {
059: return _session.getLastAccessedTime();
060: }
061:
062: public ServletContext getServletContext() {
063: return _servletContext;
064: }
065:
066: public void setMaxInactiveInterval(int i) {
067: _session.setMaxInactiveInterval(i);
068: }
069:
070: public int getMaxInactiveInterval() {
071: return _session.getMaxInactiveInterval();
072: }
073:
074: public HttpSessionContext getSessionContext() {
075: return _session.getSessionContext();
076: }
077:
078: public Object getValue(String s) {
079: return getAttribute(s);
080: }
081:
082: public String[] getValueNames() {
083: return getAttributeNamesArray();
084: }
085:
086: public void putValue(String s, Object o) {
087: setAttribute(s, o);
088: }
089:
090: public void removeValue(String s) {
091: removeAttribute(s);
092: }
093:
094: public void invalidate() {
095: removeAllAttributes();
096: }
097:
098: public boolean isNew() {
099: return _session.isNew();
100: }
101:
102: /**
103: * Since _session is transient, this method is called by {@link ScopedRequestImpl#getSession}
104: * to reinitialize it each time.
105: */
106: void setSession(HttpSession session, ServletContext cxt) {
107: _session = session;
108: _servletContext = cxt;
109: }
110:
111: /**
112: * Returns the real (outer) HttpSession.
113: */
114: public HttpSession getOuterSession() {
115: return _session;
116: }
117: }
|