001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.chain.web.servlet;
017:
018: import org.apache.commons.chain.web.MockEnumeration;
019:
020: import javax.servlet.ServletContext;
021: import javax.servlet.http.HttpSession;
022: import javax.servlet.http.HttpSessionContext;
023: import java.util.Enumeration;
024: import java.util.HashMap;
025:
026: // Mock Object for HttpSession (Version 2.3)
027: public class MockHttpSession implements HttpSession {
028:
029: public MockHttpSession() {
030: super ();
031: }
032:
033: public MockHttpSession(ServletContext servletContext) {
034: super ();
035: setServletContext(servletContext);
036: }
037:
038: protected HashMap attributes = new HashMap();
039: protected ServletContext servletContext = null;
040:
041: // --------------------------------------------------------- Public Methods
042:
043: public void setServletContext(ServletContext servletContext) {
044: this .servletContext = servletContext;
045: }
046:
047: // ---------------------------------------------------- HttpSession Methods
048:
049: public Object getAttribute(String name) {
050: return (attributes.get(name));
051: }
052:
053: public Enumeration getAttributeNames() {
054: return (new MockEnumeration(attributes.keySet().iterator()));
055: }
056:
057: public long getCreationTime() {
058: throw new UnsupportedOperationException();
059: }
060:
061: public String getId() {
062: throw new UnsupportedOperationException();
063: }
064:
065: public long getLastAccessedTime() {
066: throw new UnsupportedOperationException();
067: }
068:
069: public int getMaxInactiveInterval() {
070: throw new UnsupportedOperationException();
071: }
072:
073: public ServletContext getServletContext() {
074: return (this .servletContext);
075: }
076:
077: public HttpSessionContext getSessionContext() {
078: throw new UnsupportedOperationException();
079: }
080:
081: public Object getValue(String name) {
082: throw new UnsupportedOperationException();
083: }
084:
085: public String[] getValueNames() {
086: throw new UnsupportedOperationException();
087: }
088:
089: public void invalidate() {
090: throw new UnsupportedOperationException();
091: }
092:
093: public boolean isNew() {
094: throw new UnsupportedOperationException();
095: }
096:
097: public void putValue(String name, Object value) {
098: throw new UnsupportedOperationException();
099: }
100:
101: public void removeAttribute(String name) {
102: attributes.remove(name);
103: }
104:
105: public void removeValue(String name) {
106: throw new UnsupportedOperationException();
107: }
108:
109: public void setAttribute(String name, Object value) {
110: if (value == null) {
111: attributes.remove(name);
112: } else {
113: attributes.put(name, value);
114: }
115: }
116:
117: public void setMaxInactiveInterval(int interval) {
118: throw new UnsupportedOperationException();
119: }
120:
121: }
|