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.commandline;
018:
019: import org.apache.cocoon.environment.Session;
020:
021: import java.util.Enumeration;
022: import java.util.Hashtable;
023:
024: /**
025: *
026: * Command-line version of Http Session.
027: *
028: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
029: * @version CVS $Id: CommandLineSession.java 433543 2006-08-22 06:22:54Z crossley $
030: */
031: public final class CommandLineSession implements Session {
032:
033: private long creationTime = System.currentTimeMillis();
034:
035: private Hashtable attributes = new Hashtable();
036:
037: public CommandLineSession() {
038: }
039:
040: public long getCreationTime() {
041: return this .creationTime;
042: }
043:
044: public String getId() {
045: return "1";
046: }
047:
048: public long getLastAccessedTime() {
049: return this .creationTime;
050: }
051:
052: public void setMaxInactiveInterval(int interval) {
053: // ignored
054: }
055:
056: public int getMaxInactiveInterval() {
057: return -1;
058: }
059:
060: public Object getAttribute(String name) {
061: return this .attributes.get(name);
062: }
063:
064: public Enumeration getAttributeNames() {
065: return this .attributes.keys();
066: }
067:
068: public void setAttribute(String name, Object value) {
069: this .attributes.put(name, value);
070: }
071:
072: public void removeAttribute(String name) {
073: this .attributes.remove(name);
074: }
075:
076: public void invalidate() {
077: this .attributes.clear();
078: invalidateSession();
079: }
080:
081: public boolean isNew() {
082: return false;
083: }
084:
085: protected static CommandLineSession session;
086:
087: /**
088: * Get the current session object - if available
089: */
090: public static Session getSession(boolean create) {
091: if (create && session == null) {
092: session = new CommandLineSession();
093: }
094: return session;
095: }
096:
097: /**
098: * Invalidate the current session
099: */
100: public static void invalidateSession() {
101: session = null;
102: }
103:
104: }
|