Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package com.vogella.extensionpoint.definition;
  2.  
  3. import org.eclipse.core.runtime.CoreException;
  4. import org.eclipse.core.runtime.IConfigurationElement;
  5. import org.eclipse.core.runtime.IExtensionRegistry;
  6. import org.eclipse.core.runtime.ISafeRunnable;
  7. import org.eclipse.core.runtime.SafeRunner;
  8. import org.eclipse.e4.core.di.annotations.Execute;
  9.  
  10. public class EvaluateContributionsHandler {
  11. private static final String IGREETER_ID =
  12. "com.vogella.extensionpoint.definition.greeter";
  13. @Execute
  14. public void execute(IExtensionRegistry registry) {
  15. IConfigurationElement[] config =
  16. registry.getConfigurationElementsFor(IGREETER_ID);
  17. try {
  18. for (IConfigurationElement e : config) {
  19. System.out.println("Evaluating extension");
  20. final Object o =
  21. e.createExecutableExtension("class");
  22. if (o instanceof IGreeter) {
  23. executeExtension(o);
  24. }
  25. }
  26. } catch (CoreException ex) {
  27. System.out.println(ex.getMessage());
  28. }
  29. }
  30.  
  31. private void executeExtension(final Object o) {
  32. ISafeRunnable runnable = new ISafeRunnable() {
  33. @Override
  34. public void handleException(Throwable e) {
  35. System.out.println("Exception in client");
  36. }
  37.  
  38. @Override
  39. public void run() throws Exception {
  40. ((IGreeter) o).greet();
  41. }
  42. };
  43. SafeRunner.run(runnable);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement