001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * SessionManagerImpl.java
039: *
040: */
041:
042: package com.sun.xml.ws.runtime.util;
043:
044: import java.util.Set;
045: import java.util.Hashtable;
046:
047: /**
048: * In memory implementation of <code>SessionManager</code>
049: *
050: * @author Mike Grogan
051: */
052: public class SessionManagerImpl extends SessionManager {
053:
054: /**
055: * Map of session id --> session
056: */
057: private Hashtable<String, Session> sessionMap = new Hashtable<String, Session>();
058:
059: /** Creates a new instance of SessionManagerImpl */
060: public SessionManagerImpl() {
061:
062: }
063:
064: /**
065: * Returns an existing session identified by the Key else null
066: *
067: * @param key The Session key.
068: * @returns The Session with the given key. <code>null</code> if none exists.
069: */
070: public Session getSession(String key) {
071: return sessionMap.get(key);
072: }
073:
074: /**
075: * Returns the Set of valid Session keys.
076: *
077: * @returns The Set of keys.
078: */
079: public Set<String> getKeys() {
080: return sessionMap.keySet();
081: }
082:
083: /**
084: * Removed the Session with the given key.
085: *
086: * @param key The key of the Session to be removed.
087: */
088: public void terminateSession(String key) {
089: sessionMap.remove(key);
090: }
091:
092: /**
093: * Creates a Session with the given key, using a new instance
094: * of the specified Class as a holder for user-defined data. The
095: * specified Class must have a default ctor.
096: *
097: * @param key The Session key to be used.
098: * @returns The new Session.. <code>null</code> if the given
099: * class cannot be instantiated.
100: *
101: */
102: public Session createSession(String key, Class clasz) {
103: Session sess;
104: try {
105: sess = new Session(this , key, clasz.newInstance());
106: } catch (InstantiationException e) {
107: return null;
108: } catch (IllegalAccessException ee) {
109: return null;
110: }
111:
112: sessionMap.put(key, sess);
113: return sess;
114:
115: }
116:
117: /**
118: * Creates a Session with the given key, using the specified Object
119: * as a holder for user-defined data.
120: *
121: * @param key The Session key to be used.
122: * @param obj The object to use as a holder for user data in the session.
123: * @returns The new Session.
124: *
125: */
126: public Session createSession(String key, Object obj) {
127:
128: Session sess = new Session(this , key, obj);
129: sessionMap.put(key, sess);
130: return sess;
131: }
132:
133: /**
134: * Creates a Session with the given key, using an instance of
135: * java.util.Hashtable<String, String> asa holder for user-defined data.
136: *
137: * @param key The Session key to be used.
138: * @returns The new Session.
139: *
140: */
141: public Session createSession(String key) {
142: return createSession(key,
143: new java.util.Hashtable<String, String>());
144: }
145:
146: /**
147: * Does nothing in this implementation.
148: *
149: * @param key The key of the session to be saved
150: */
151: public void saveSession(String key) {
152: }
153:
154: }
|