View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.exception;
18  
19  import java.util.Locale;
20  import java.util.ResourceBundle;
21  
22  import org.apache.jetspeed.i18n.KeyedMessage;
23  
24  
25  /***
26   * Occurs when anything unexpected happens within Jetspeed.Any defined exceptions
27   * within Jetspeed should always extend from this.
28   * 
29   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
30   * @version $Id: JetspeedException.java 516448 2007-03-09 16:25:47Z ate $
31   **/
32  
33  public class JetspeedException extends Exception 
34  {
35      public static final String KEYED_MESSAGE_BUNDLE = "org.apache.jetspeed.exception.JetspeedExceptionMessages";
36      
37      private KeyedMessage keyedMessage;
38      
39      public JetspeedException() 
40      {
41          super();
42      }
43      
44      public JetspeedException(String message) 
45      {
46          super(message);
47      }
48      
49      public JetspeedException(KeyedMessage typedMessage) 
50      {
51          super(typedMessage.getMessage());
52          this.keyedMessage = typedMessage;
53      }
54      
55      public JetspeedException(Throwable nested)
56      {
57          super(nested);
58      }
59      
60      public JetspeedException(String msg, Throwable nested)
61      {
62          super(msg, nested);
63      }
64      
65      public JetspeedException(KeyedMessage keyedMessage, Throwable nested)
66      {
67          super(keyedMessage.getMessage(), nested);
68          this.keyedMessage = keyedMessage;
69      }
70      
71      public KeyedMessage getKeyedMessage()
72      {
73          return keyedMessage;
74      }
75      
76      public String getMessage()
77      {
78          if ( keyedMessage != null )
79          {
80              return keyedMessage.getMessage();
81          }
82          return super.getMessage();
83      }
84      
85      public String getMessage(ResourceBundle bundle)
86      {
87          if ( keyedMessage != null )
88          {
89              return keyedMessage.getMessage(bundle);
90          }
91          return super.getMessage();
92      }
93  
94      public String getMessage(Locale locale)
95      {
96          if ( keyedMessage != null )
97          {
98              return keyedMessage.getMessage(locale);
99          }
100         return super.getMessage();
101     }
102 }