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: package org.apache.cocoon.environment.mock;
018:
019: import java.util.Enumeration;
020: import java.util.Hashtable;
021:
022: import junit.framework.AssertionFailedError;
023:
024: import org.apache.cocoon.environment.Session;
025:
026: public class MockSession implements Session {
027:
028: private long creationtime = System.currentTimeMillis();
029: private String id = "MockSession";
030: private long lastaccessedtime = System.currentTimeMillis();
031: private int maxinactiveinterval = -1;
032: private Hashtable attributes = new Hashtable();
033: private boolean valid = true;
034:
035: public long getCreationTime() {
036: checkValid();
037: return creationtime;
038: }
039:
040: public void setId(String id) {
041: this .id = id;
042: }
043:
044: public String getId() {
045: checkValid();
046: return id;
047: }
048:
049: public long getLastAccessedTime() {
050: checkValid();
051: return lastaccessedtime;
052: }
053:
054: public void setMaxInactiveInterval(int interval) {
055: checkValid();
056: this .maxinactiveinterval = interval;
057: }
058:
059: public int getMaxInactiveInterval() {
060: checkValid();
061: return maxinactiveinterval;
062: }
063:
064: public Object getAttribute(String name) {
065: checkValid();
066: return attributes.get(name);
067: }
068:
069: public Enumeration getAttributeNames() {
070: checkValid();
071: return attributes.keys();
072: }
073:
074: public void setAttribute(String name, Object value) {
075: checkValid();
076: attributes.put(name, value);
077: }
078:
079: public void removeAttribute(String name) {
080: checkValid();
081: attributes.remove(name);
082: }
083:
084: public void invalidate() {
085: checkValid();
086: this .valid = false;
087: }
088:
089: public boolean isNew() {
090: checkValid();
091: return false;
092: }
093:
094: private void checkValid() throws IllegalStateException {
095: if (!valid)
096: throw new AssertionFailedError(
097: "session has been invalidated!");
098: }
099:
100: public boolean isValid() {
101: return valid;
102: }
103: }
|