View Javadoc

1   package com.explosion.utilities.exception;
2   
3   /*
4    * =============================================================================
5    * 
6    * Copyright 2004 Stephen Cowx
7    * 
8    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
9    * use this file except in compliance with the License. You may obtain a copy of
10   * the License at
11   * 
12   * http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   * 
20   * =============================================================================
21   */
22  
23  import java.util.Vector;
24  
25  /***
26   * @author Stephen Cowx
27   * @version 1.0
28   */
29  
30  public class ExceptionManager
31  {
32  
33      private Vector exceptionHandlers = new Vector();
34  
35      private DefaultExceptionHandler defaultHandler;
36  
37      /***
38       * Method addExceptionHandler. Adds an ExceptionHandler to the manager. All
39       * exceptions managed by this manager willbe passedto this exception
40       * handler.
41       * 
42       * @param handler
43       */
44      public void addExceptionHandler(ExceptionHandler handler)
45      {
46          exceptionHandlers.addElement(handler);
47      }
48  
49      /***
50       * Method removeExceptionHandler. Removes an exceptionHandler from this
51       * manager.
52       * 
53       * @param handler
54       */
55      public void removeExceptionHandler(ExceptionHandler handler)
56      {
57          exceptionHandlers.remove(handler);
58      }
59  
60      /***
61       * Method manageException. Distributes this exception to all of the
62       * registered ExceptionHandlers. If there are none itwilluse
63       * defaultExceptionHandler. It is usually not mandatory that the Frame is
64       * not null.
65       * 
66       * @param e
67       * @param message
68       * @param owner
69       */
70      public void manageException(Throwable e, String message)
71      {
72          if (exceptionHandlers.size() < 1 )
73          {
74  	        if (defaultHandler == null)
75              {
76  	            defaultHandler = new DefaultExceptionHandler();
77              }
78  	        defaultHandler.handleException(e, message);
79          }
80          else
81          {
82              for (int i = 0; i < exceptionHandlers.size(); i++)
83              {
84                  ((ExceptionHandler) exceptionHandlers.elementAt(i)).handleException(e, message);
85              }
86          }
87      }
88  }