001/* 002 * jDTAUS Core RI Servlet Container 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.container.ri.servlet; 022 023import java.io.Serializable; 024import java.util.Collection; 025import java.util.Collections; 026import javax.servlet.http.HttpSession; 027import org.jdtaus.core.container.Context; 028 029/** 030 * HTTP session {@code Context} implementation. 031 * <p>This implementation needs to be configured manually for use by 032 * {@link org.jdtaus.core.container.ContextFactory#newContext()}. See the 033 * factory for how to configure this class to be used.</p> 034 * 035 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 036 * @version $JDTAUS: HttpSessionContext.java 8641 2012-09-27 06:45:17Z schulte $ 037 * 038 * @see ServletFilter 039 */ 040public class HttpSessionContext implements Context 041{ 042 //--Context----------------------------------------------------------------- 043 044 public final Collection getObjectKeys() 045 { 046 return Collections.list( this.getSession().getAttributeNames() ); 047 } 048 049 public final Object getObject( final String key ) 050 { 051 if ( key == null ) 052 { 053 throw new NullPointerException( "key" ); 054 } 055 056 return this.getSession().getAttribute( key ); 057 } 058 059 public final Object setObject( final String key, final Object o ) 060 { 061 if ( key == null ) 062 { 063 throw new NullPointerException( "key" ); 064 } 065 066 final Object old = this.getSession().getAttribute( key ); 067 this.getSession().setAttribute( key, o ); 068 069 return old; 070 } 071 072 public final Object removeObject( final String key ) 073 { 074 if ( key == null ) 075 { 076 throw new NullPointerException( "key" ); 077 } 078 079 final Object old = this.getSession().getAttribute( key ); 080 this.getSession().removeAttribute( key ); 081 082 return old; 083 } 084 085 public final Object getAttribute( final String key ) 086 { 087 return this.getObject( key ); 088 } 089 090 public final Object setAttribute( final String key, final Serializable o ) 091 { 092 return this.setObject( key, o ); 093 } 094 095 public final Object removeAttribute( String key ) 096 { 097 return this.removeObject( key ); 098 } 099 100 //-----------------------------------------------------------------Context-- 101 //--HttpSessionContext------------------------------------------------------ 102 103 /** @see ServletFilter#getHttpSession() */ 104 public HttpSession getSession() 105 { 106 return ServletFilter.getHttpSession(); 107 } 108 109 //------------------------------------------------------HttpSessionContext-- 110}