KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > exceptionhandler > ExceptionHandlerEPProcessor


1 /*
2  * Created on Sep 23, 2004
3  *
4  */

5 package com.nightlabs.rcp.exceptionhandler;
6
7 import org.eclipse.core.runtime.IConfigurationElement;
8
9 import com.nightlabs.rcp.extensionpoint.AbstractEPProcessor;
10 import com.nightlabs.rcp.extensionpoint.EPProcessorException;
11
12 /**
13  * Helper class processes exceptionHandler extension-point.
14  * Finds elements and makes registrations in {@link com.nightlabs.rcp.exceptionhandler.ExceptionHandlerRegistry}.
15  *
16  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
17  */

18 public class ExceptionHandlerEPProcessor extends AbstractEPProcessor{
19     
20     public static final String JavaDoc ExtensionPointID = "com.nightlabs.base.exceptionhandler";
21     /**
22      * Processes exceptionHandler extension-point elements.
23      * For each element one instance of exceptionHandler.class is registered
24      * in the {@link ExceptionHandlerRegistry}.
25      * @param element
26      * @throws EPProcessorException
27      */

28     public void processElement(IConfigurationElement element)
29     throws EPProcessorException
30     {
31         try{
32             if (element.getName().toLowerCase().equals("exceptionhandler")){
33                 String JavaDoc targetType = element.getAttribute("targetType");
34                 String JavaDoc handlerClassStr = element.getAttribute("class");
35                 IExceptionHandler handler = (IExceptionHandler) element.createExecutableExtension("class");
36                 if (!IExceptionHandler.class.isAssignableFrom(handler.getClass()))
37                 throw new IllegalArgumentException JavaDoc("Specified class for element exceptionHandler must implement "+IExceptionHandler.class.getName()+". "+handler.getClass().getName()+" does not.");
38                 ExceptionHandlerRegistry.getSharedInstance().addExceptionHandler(targetType,handler);
39             }
40             else {
41                 // wrong element according to schema, probably checked earlier
42
throw new IllegalArgumentException JavaDoc("Element "+element.getName()+" is not supported by extension-point "+ExtensionPointID);
43             }
44         }catch(Throwable JavaDoc e){
45             throw new EPProcessorException(e);
46         }
47     }
48
49     /* (non-Javadoc)
50      * @see com.nightlabs.rcp.extensionpoint.AbstractEPProcessor#getExtensionPointID()
51      */

52     public String JavaDoc getExtensionPointID() {
53         return ExtensionPointID;
54     }
55 }
56
Popular Tags