View Javadoc

1   /*
2    *  jDTAUS Core RI Servlet Container
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.core.container.ri.servlet;
22  
23  import java.io.ObjectStreamException;
24  import java.util.Locale;
25  import org.jdtaus.core.container.ContainerFactory;
26  
27  /**
28   * Gets thrown when the {@code HttpSession} for a thread of execution is
29   * {@code null}.
30   *
31   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
32   * @version $JDTAUS: SessionLostException.java 8641 2012-09-27 06:45:17Z schulte $
33   */
34  public class SessionLostException extends IllegalStateException
35  {
36      //--Constants---------------------------------------------------------------
37  
38      /** Serial version UID for backwards compatibility with 1.0.x classes. */
39      private static final long serialVersionUID = -7663896854184348690L;
40  
41      //---------------------------------------------------------------Constants--
42      //--SessionLostException----------------------------------------------------
43  
44      /**
45       * The locale of the exception.
46       * @serial
47       */
48      private Locale locale;
49  
50      /***
51       * The thread accessing the session.
52       * @serial
53       */
54      private Thread thread;
55  
56      /**
57       * Creates a new instance of {@code SessionLostException} taking
58       * the {@code Thread} trying to access the session.
59       *
60       * @param thread the {@code Thread} accessing the session.
61       * @deprecated Replaced by {@link SessionLostException#SessionLostException(java.util.Locale, java.lang.Thread) }
62       */
63      public SessionLostException( final Thread thread )
64      {
65          super();
66          this.thread = thread;
67          this.locale = Locale.getDefault();
68      }
69  
70      /**
71       * Creates a new instance of {@code SessionLostException} taking
72       * the {@code Locale} of the exception and the {@code Thread} trying to
73       * access the session.
74       *
75       * @param locale The locale of the exception.
76       * @param thread the {@code Thread} accessing the session.
77       */
78      public SessionLostException( final Locale locale, final Thread thread )
79      {
80          super();
81          this.locale = locale;
82          this.thread = thread;
83      }
84  
85      /**
86       * Gets the thread accessing the session.
87       *
88       * @return the thread accessing the session or {@code null}.
89       */
90      public Thread getThread()
91      {
92          return this.thread;
93      }
94  
95      /**
96       * Returns the detail message string of this throwable.
97       *
98       * @return the detail message string of this {@code Throwable} instance or
99       * {@code null}.
100      */
101     public String getMessage()
102     {
103         return this.getSessionLostMessage(
104             this.locale, this.thread == null
105                          ? null : this.thread.getName() );
106 
107     }
108 
109     //----------------------------------------------------SessionLostException--
110     //--Serializable------------------------------------------------------------
111 
112     /**
113      * Takes care of initializing fields when constructed from an 1.0.x object
114      * stream.
115      *
116      * @throws ObjectStreamException if resolution fails.
117      */
118     private Object readResolve() throws ObjectStreamException
119     {
120         if ( this.locale == null )
121         {
122             this.locale = Locale.getDefault();
123         }
124 
125         return this;
126     }
127 
128     //------------------------------------------------------------Serializable--
129     //--Messages----------------------------------------------------------------
130 
131 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
132     // This section is managed by jdtaus-container-mojo.
133 
134     /**
135      * Gets the text of message <code>sessionLost</code>.
136      * <blockquote><pre>Keine Sitzung für Thread {0}.</pre></blockquote>
137      * <blockquote><pre>No session available for thread {0}.</pre></blockquote>
138      *
139      * @param locale The locale of the message instance to return.
140      * @param threadName Name of the thread without session.
141      *
142      * @return Information about the thread without session.
143      */
144     private String getSessionLostMessage( final Locale locale,
145             final java.lang.String threadName )
146     {
147         return ContainerFactory.getContainer().
148             getMessage( this, "sessionLost", locale,
149                 new Object[]
150                 {
151                     threadName
152                 });
153 
154     }
155 
156 // </editor-fold>//GEN-END:jdtausMessages
157 
158     //----------------------------------------------------------------Messages--
159 }