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 ServletContext} for a thread of execution is
29 * {@code null}.
30 *
31 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
32 * @version $JDTAUS: ContextLostException.java 8641 2012-09-27 06:45:17Z schulte $
33 */
34 public class ContextLostException extends IllegalStateException
35 {
36 //--Constants---------------------------------------------------------------
37
38 /** Serial version UID for backwards compatibility with 1.0.x classes. */
39 private static final long serialVersionUID = -6008133560882440501L;
40
41 //---------------------------------------------------------------Constants--
42 //--ContextLostException----------------------------------------------------
43
44 /**
45 * The locale of the exception.
46 * @serial
47 */
48 private Locale locale;
49
50 /***
51 * The thread accessing the context.
52 * @serial
53 */
54 private Thread thread;
55
56 /**
57 * Creates a new instance of {@code ContextLostException} taking
58 * the {@code Thread} trying to access the context.
59 *
60 * @param thread The {@code Thread} accessing the context.
61 * @deprecated Replaced by {@link ContextLostException#ContextLostException(java.util.Locale, java.lang.Thread) }
62 */
63 public ContextLostException( final Thread thread )
64 {
65 super();
66 this.locale = Locale.getDefault();
67 this.thread = thread;
68 }
69
70 /**
71 * Creates a new instance of {@code ContextLostException} taking
72 * the {@code Locale} of the exception and the {@code Thread} trying to
73 * access the context.
74 *
75 * @param locale The locale of the exception.
76 * @param thread The {@code Thread} accessing the context.
77 */
78 public ContextLostException( 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 context.
87 *
88 * @return the thread accessing the context 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.getContextLostMessage(
104 this.locale, this.thread == null
105 ? null : this.thread.getName() );
106
107 }
108
109 //----------------------------------------------------ContextLostException--
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>contextLost</code>.
136 * <blockquote><pre>Kein Context für Thread {0}.</pre></blockquote>
137 * <blockquote><pre>No context 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 context.
141 *
142 * @return Information about the thread without context.
143 */
144 private String getContextLostMessage( final Locale locale,
145 final java.lang.String threadName )
146 {
147 return ContainerFactory.getContainer().
148 getMessage( this, "contextLost", locale,
149 new Object[]
150 {
151 threadName
152 });
153
154 }
155
156 // </editor-fold>//GEN-END:jdtausMessages
157
158 //----------------------------------------------------------------Messages--
159 }