View Javadoc

1   /*
2    * $Id: SessionImpl.java 113 2004-10-22 19:22:56Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.command;
24  
25  import javax.servlet.http.HttpSession;
26  
27  /**
28   * Implementation of <code>Session</code> interface.
29   *
30   * @author  Jose M. Palomar
31   * @version $Revision: 113 $
32   */
33  public final class SessionImpl implements Session {
34  
35      // Constants
36  
37      // Fields
38      /**
39       * Source HttpSession.
40       */
41      private final HttpSession httpSession;
42  
43      // Constructors
44      /**
45       * Constructs a new <code>SessionImpl</code> object.
46       *
47       * @param httpSession HttpSession source HttpSession.
48       */
49      public SessionImpl(HttpSession httpSession) {
50          this.httpSession = httpSession;
51      }
52  
53      // Methods
54      /**
55       * Returns a string containing the unique identifier assigned to this session.
56       *
57       * @return String string containing the unique identifier assigned to this
58       * session.
59       * @see org.talika.tarsis.command.Session#getId()
60       */
61      public String getId() {
62          return httpSession.getId();
63      }
64  
65      /**
66       * Binds an object to this session, using the name specified. If an object of
67       * the same name is already bound to the session, the object is replaced.
68       *
69       * @param name String the name to which the object is bound; cannot be
70       * <code>null</code>.
71       * @param value Object the object to be bound.
72       * @see org.talika.tarsis.command.Session#setAttribute(String, Object)
73       */
74      public void setAttribute(String name, Object value) {
75          httpSession.setAttribute(name, value);
76      }
77  
78      /**
79       * Returns the object bound with the specified name in this session, or
80       * <code>null</code> if no object is bound under the name.
81       *
82       * @param name String a string specifying the name of the object.
83       * @return Object the object with the specified name.
84       * @see org.talika.tarsis.command.Session#getAttribute(String)
85       */
86      public Object getAttribute(String name) {
87          return httpSession.getAttribute(name);
88      }
89  
90      /**
91       * Removes the object bound with the specified name from this session. If the
92       * session does not have an object bound with the specified name, this method
93       * does nothing.
94       *
95       * @param name String the name of the object to remove from this session.
96       * @see org.talika.tarsis.command.Session#removeAttribute(String)
97       */
98      public void removeAttribute(String name) {
99          httpSession.removeAttribute(name);
100     }
101 
102 }