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   * Base exception for all RuntimeExceptions defined within Jetspeed.
27   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
28   */
29  public class JetspeedRuntimeException extends RuntimeException
30  {
31  
32      public static final String KEYED_MESSAGE_BUNDLE = "org.apache.jetspeed.exception.JetspeedExceptionMessages";
33      
34      private KeyedMessage keyedMessage;
35      
36      /***
37       * 
38       */
39      public JetspeedRuntimeException()
40      {
41          super();
42      }
43  
44      /***
45       * @param arg0
46       */
47      public JetspeedRuntimeException(String arg0)
48      {
49          super(arg0);
50      }
51  
52      public JetspeedRuntimeException(KeyedMessage typedMessage) 
53      {
54          super(typedMessage.getMessage());
55          this.keyedMessage = typedMessage;
56      }
57      
58      /***
59       * @param arg0
60       */
61      public JetspeedRuntimeException(Throwable arg0)
62      {
63          super(arg0);
64      }
65  
66      /***
67       * @param arg0
68       * @param arg1
69       */
70      public JetspeedRuntimeException(String arg0, Throwable arg1)
71      {
72          super(arg0, arg1);
73      }
74  
75      public JetspeedRuntimeException(KeyedMessage keyedMessage, Throwable nested)
76      {
77          super(keyedMessage.getMessage(), nested);
78          this.keyedMessage = keyedMessage;
79      }
80      
81      public KeyedMessage getKeyedMessage()
82      {
83          return keyedMessage;
84      }
85      
86      public String getMessage()
87      {
88          if ( keyedMessage != null )
89          {
90              return keyedMessage.getMessage();
91          }
92          return super.getMessage();
93      }
94      
95      public String getMessage(ResourceBundle bundle)
96      {
97          if ( keyedMessage != null )
98          {
99              return keyedMessage.getMessage(bundle);
100         }
101         return super.getMessage();
102     }
103 
104     public String getMessage(Locale locale)
105     {
106         if ( keyedMessage != null )
107         {
108             return keyedMessage.getMessage(locale);
109         }
110         return super.getMessage();
111     }
112 }