From be4f78978faba3d3ceb88df02a7f93a2e09ff1e0 Mon Sep 17 00:00:00 2001 From: Kenji Hosokawa Date: Tue, 3 Aug 2021 18:42:39 +0900 Subject: Initial commit Bug-AGL: SPEC-4033 Signed-off-by: Kenji Hosokawa --- .../tool/editor/util/ExtensionModuleManager.java | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 rba.tool.editor/src/rba/tool/editor/util/ExtensionModuleManager.java (limited to 'rba.tool.editor/src/rba/tool/editor/util/ExtensionModuleManager.java') diff --git a/rba.tool.editor/src/rba/tool/editor/util/ExtensionModuleManager.java b/rba.tool.editor/src/rba/tool/editor/util/ExtensionModuleManager.java new file mode 100644 index 0000000..966acf0 --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/util/ExtensionModuleManager.java @@ -0,0 +1,63 @@ +package rba.tool.editor.util; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import com.google.inject.Module; + +public class ExtensionModuleManager { + public static final ExtensionModuleManager INSTANCE = new ExtensionModuleManager(); + + private static final String EXTENSION_POINT = "rba.tool.editor.rbaToolEditorExtensionModule"; //$NON-NLS-1$ + + private static final String EXTENSION_POINT_ELEMENT = "extensionModule"; //$NON-NLS-1$ + + private static final String EXTENSION_POINT_ELEMENT_ATTRIBUTE = "class"; //$NON-NLS-1$ + + private List constraintProviders; + + private ExtensionModuleManager() { + } + + public List getExtensionModules() { + if (constraintProviders == null) { + constraintProviders = new ArrayList(); + init(); + } + return constraintProviders; + } + + private void init() { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extensionPoint = registry.getExtensionPoint(EXTENSION_POINT); // $NON-NLS-1$ + IExtension[] extensions = extensionPoint.getExtensions(); + + List providerList = new ArrayList(); + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] elements = extensions[i].getConfigurationElements(); + for (int j = 0; j < elements.length; j++) { + IConfigurationElement element = elements[j]; + String elementName = element.getName(); + if (elementName.equalsIgnoreCase(EXTENSION_POINT_ELEMENT)) { // $NON-NLS-1$ + try { + Object provider = element.createExecutableExtension(EXTENSION_POINT_ELEMENT_ATTRIBUTE); // $NON-NLS-1$ + if (provider instanceof Module) { + Module factory = (Module) provider; + providerList.add(factory); + } + } catch (CoreException e) { + // do nothing + } + } + } + } + constraintProviders.addAll(providerList); + } +} -- cgit 1.2.3-korg