1 6 package com.nightlabs.rcp.extensionpoint; 7 8 import org.eclipse.core.runtime.IConfigurationElement; 9 import org.eclipse.core.runtime.IExtension; 10 import org.eclipse.core.runtime.IExtensionPoint; 11 import org.eclipse.core.runtime.IExtensionRegistry; 12 import org.eclipse.core.runtime.Platform; 13 14 31 public abstract class AbstractEPProcessor 32 implements IEPProcessor 33 { 34 35 public abstract String getExtensionPointID(); 36 37 public abstract void processElement(IConfigurationElement element) throws EPProcessorException; 38 39 private boolean processed = false; 40 public boolean isProcessed() { 41 return processed; 42 } 43 44 private boolean processing = false; 45 46 protected boolean isProcessing() { 47 return processing; 48 } 49 50 public synchronized void process() throws EPProcessorException{ 51 processing = true; 52 try { 53 try{ 54 IExtensionRegistry registry = Platform.getExtensionRegistry(); 55 IExtensionPoint extensionPoint = registry.getExtensionPoint(getExtensionPointID()); 56 if (extensionPoint == null) { 57 throw new EPProcessorException( 58 "Unable to resolve extension-point: " + getExtensionPointID()); 59 } 60 61 IExtension[] extensions = extensionPoint.getExtensions(); 62 for (int i = 0; i < extensions.length; i++) { 64 IExtension extension = extensions[i]; 65 IConfigurationElement[] elements = 66 extension.getConfigurationElements(); 67 for (int j = 0; j < elements.length; j++) { 69 IConfigurationElement element = elements[j]; 70 processElement(element); 71 } 72 } 73 processed = true; 74 }catch(Throwable e){ 75 if (e instanceof EPProcessorException) 76 throw (EPProcessorException)e; 77 else 78 throw new EPProcessorException(e); 79 } 80 } finally { 81 processing = false; 82 } 83 } 84 85 89 public void checkProcessing() 90 { 91 if (!isProcessed()) { 92 try { 93 process(); 94 } catch (EPProcessorException e) { 95 throw new RuntimeException (e); 96 } 97 } 98 } 99 100 } 101 | Popular Tags |