@Override public void configure(ConfigurationElement config) throws CoreException { super.configure(config); ConfigurationElement itemsElement = config.getChild(ELEMENT_NAME_ITEMS); if (itemsElement == null) { return; } ConfigurationElement[] children = itemsElement.getChildren(); String[] groupItems = new String[children.length]; for (int i = 0; i < children.length; i++) { ConfigurationElement child = children[i]; String childName = child.getName(); switch (childName) { case ELEMENT_NAME_ACTION_ID: case ELEMENT_NAME_ACTION_GROUP_ID: groupItems[i] = child.getValue().trim(); break; case ELEMENT_NAME_SEPARATOR: groupItems[i] = null; break; default: Module declaringModule = config.getDeclaringExtension().getDeclaringModule(); throw new CoreException(String.format("Module [%s]: '%s' is an unknown 'groupItems' element", declaringModule.getName(), childName)); } } setProperty(ACTION_KEY_GROUP_ITEMS, groupItems); }
@Override public void configure(ConfigurationElement config) throws CoreException { super.configure(config); module = config.getDeclaringExtension().getDeclaringModule(); ConfigurationElement script = config.getChild("script"); if (script != null) { String scriptType = script.getAttribute("type"); if (StringUtils.isNotNullAndNotEmpty(scriptType)) { type = scriptType; } String scriptSrc = script.getAttribute("src"); if (StringUtils.isNotNullAndNotEmpty(scriptSrc)) { src = scriptSrc; } String scriptCode = script.getValue(); if (StringUtils.isNotNullAndNotEmpty(scriptCode)) { code = scriptCode; } System.out.printf("ScriptAction [%s] of module [%s]:%n", getText(), module.getSymbolicName()); System.out.printf(" type = [%s]%n", this.type); System.out.printf(" src = [%s]%n", this.src); System.out.printf(" code = [%s]%n", this.code); } }
/** * Gets the resource string for the given command command-ID and command property name. */ protected String getConfigString(ConfigurationElement config, String elementName) { String value = null; ConfigurationElement child = config.getChild(elementName); if (child != null) { value = child.getValue(); } return value; }
private void registerHelpSet(ConfigurationElement helpSetElement, Module declaringModule) { String helpSetPath = null; ConfigurationElement pathElem = helpSetElement.getChild("path"); if (pathElem != null) { helpSetPath = pathElem.getValue(); helpSetPath = helpSetElement.getAttribute("path"); ConfigurationElement idElem = helpSetElement.getChild("id"); if (idElem != null) { helpSetId = idElem.getValue(); } else { helpSetId = "helpSet$" + helpSetNo; ConfigurationElement parentElem = helpSetElement.getChild("parent"); if (parentElem != null) { helpSetParent = parentElem.getValue(); } else { helpSetParent = ""; // = root
public static <T> List<T> loadExecutableExtensions(ModuleContext moduleContext, String extensionPointId, String elementName, Class<T> extensionType) { Module module = moduleContext.getModule(); ExtensionPoint extensionPoint = module.getExtensionPoint(extensionPointId); ConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements(); List<T> executableExtensions = new ArrayList<>(32); for (ConfigurationElement configurationElement : configurationElements) { ConfigurationElement[] children = configurationElement.getChildren(elementName); for (ConfigurationElement child : children) { try { ModuleState moduleState = child.getDeclaringExtension().getDeclaringModule().getState(); if (moduleState.isOneOf(ModuleState.STARTING, ModuleState.RESOLVED)) { T executableExtension = child.createExecutableExtension(extensionType); executableExtensions.add(executableExtension); } } catch (CoreException e) { moduleContext.getLogger().log(Level.SEVERE, e.getMessage(), e); } } } return executableExtensions; }
private <T> T loadObjectInstance(ConfigurationElement config, Class<? extends T> baseClass, String implClassName) throws CoreException { Class<?> derivedClass; try { derivedClass = config.getDeclaringExtension().getDeclaringModule().loadClass(implClassName); } catch (ClassNotFoundException e) { String msg = MessageFormat.format("[{0}]: Not able to load class [{1}]", config.getDeclaringExtension().getDeclaringModule().getName(), implClassName); throw new CoreException(msg, e); } else { String msg = MessageFormat.format("[{0}]: Specified class [{1}] must be derived from [{2}]", config.getDeclaringExtension().getDeclaringModule().getName(), implClassName, baseClass.getName()); } catch (Exception e) { String msg = MessageFormat.format("[{0}]: Not able to create new instance of class [{1}]", config.getDeclaringExtension().getDeclaringModule().getName(), interactorClass.getName()); throw new CoreException(msg, e);
throw new CoreException(String.format("Missing configuration element 'applicationId' in element '%s'.", config.getName())); Module declaringModule = config.getDeclaringExtension().getDeclaringModule(); if (displayName == null) { displayName = declaringModule.getName();
private static void registerRGBProfiles(ModuleContext moduleContext) throws CoreException { ExtensionPoint rgbExtensionPoint = moduleContext.getModule().getExtensionPoint("rgbProfiles"); Extension[] rgbExtensions = rgbExtensionPoint.getExtensions(); RGBImageProfileManager profileManager = RGBImageProfileManager.getInstance(); for (Extension extension : rgbExtensions) { ConfigurationElement confElem = extension.getConfigurationElement(); ConfigurationElement[] rgbElements = confElem.getChildren("rgbProfile"); for (ConfigurationElement rgbElement : rgbElements) { RGBImageProfile rgbImageProfile = new RGBImageProfile(); rgbImageProfile.configure(rgbElement); profileManager.addProfile(rgbImageProfile); } } }
Class<?> aClass; try { aClass = config.getDeclaringExtension().getDeclaringModule().loadClass(writerPluginClassName); } catch (ClassNotFoundException e) { String msg = MessageFormat.format("[{0}]: Not able to load class [{1}]", config.getDeclaringExtension().getDeclaringModule().getName(), writerPluginClassName); throw new CoreException(msg, e); } else { String msg = MessageFormat.format("[{0}]: Specified class [{1}] must be derived from [{2}]", config.getDeclaringExtension().getDeclaringModule().getName(), writerPluginClassName, ProductWriterPlugIn.class.getName()); } catch (Exception e) { String msg = MessageFormat.format("[{0}]: Specified class [{1}] could not be instantiated", config.getDeclaringExtension().getDeclaringModule().getName(), writerPluginClass.getName()); throw new CoreException(msg);
private void registerHelpSets(ModuleContext moduleContext) { this.helpSetRegistry = new TreeNode<>(""); ExtensionPoint hsExtensionPoint = moduleContext.getModule().getExtensionPoint("helpSets"); Extension[] hsExtensions = hsExtensionPoint.getExtensions(); for (Extension extension : hsExtensions) { ConfigurationElement confElem = extension.getConfigurationElement(); ConfigurationElement[] helpSetElements = confElem.getChildren("helpSet"); for (ConfigurationElement helpSetElement : helpSetElements) { final Module declaringModule = extension.getDeclaringModule(); if (declaringModule.getState().is(ModuleState.RESOLVED)) { registerHelpSet(helpSetElement, declaringModule); } } } addNodeToHelpSys(helpSetRegistry); }
private static String getChildValue(ConfigurationElement config, String childName) throws CoreException { ConfigurationElement child = config.getChild(childName); if (child != null) { return child.getValue(); } else { throw new CoreException("Configuration element [" + childName + "] does not exist"); } } }
private void configureInteractor(ConfigurationElement config) throws CoreException { String interactorClassName = getConfigString(config, INTERACTOR_ELEMENT_NAME); if (interactorClassName != null) { Interactor interactor = loadObjectInstance(config, Interactor.class, interactorClassName); interactor.addListener(activationHandler); String interactorListenerClassName = getConfigString(config, INTERACTOR_LISTENER_ELEMENT_NAME); if (interactorListenerClassName != null) { InteractorListener interactorListener = loadObjectInstance(config, InteractorListener.class, interactorListenerClassName); interactor.addListener(interactorListener); } setInteractor(interactor); } else { String msg = MessageFormat.format("[{0}]: Missing element [{1}] whose value must be an instance of [{2}]", config.getDeclaringExtension().getDeclaringModule().getName(), INTERACTOR_ELEMENT_NAME, Interactor.class.getName()); throw new CoreException(msg); } }
rgbaExpressions[B] = getChildValue(config, "blue"); ConfigurationElement child = config.getChild("alpha"); String alpha = null; if (child != null) { alpha = child.getValue(); ConfigurationElement patternConfig = config.getChild("pattern"); if (patternConfig != null) { pattern = new String[3]; ConfigurationElement productType = patternConfig.getChild("productType"); ConfigurationElement productName = patternConfig.getChild("productName"); ConfigurationElement productDesc = patternConfig.getChild("productDesc"); if (productType != null) { pattern[0] = productType.getValue(); pattern[1] = productName.getValue(); pattern[2] = productDesc.getValue();
super.configure(config); moduleName = config.getDeclaringExtension().getDeclaringModule().getName();
ConfigurationElement productDescConfig = mock(ConfigurationElement.class); when(nameConfig.getValue()).thenReturn("test_name"); when(redConfig.getValue()).thenReturn("radiance_12"); when(greenConfig.getValue()).thenReturn("radiance_6"); when(blueConfig.getValue()).thenReturn("radiance_2"); when(productTypeConfig.getValue()).thenReturn("MER_*_1*"); when(productNameConfig.getValue()).thenReturn("ATS_*_1*"); when(productDescConfig.getValue()).thenReturn(""); when(config.getChild("name")).thenReturn(nameConfig); when(config.getChild("red")).thenReturn(redConfig); when(config.getChild("green")).thenReturn(greenConfig); when(config.getChild("blue")).thenReturn(blueConfig); when(config.getChild("alpha")).thenReturn(null); when(config.getChild("pattern")).thenReturn(patternConfig); when(patternConfig.getChild("productType")).thenReturn(productTypeConfig); when(patternConfig.getChild("productName")).thenReturn(productNameConfig); when(patternConfig.getChild("productDesc")).thenReturn(productDescConfig);
@Test public void testConfigure_withoutPattern() throws Exception { RGBImageProfile profile = new RGBImageProfile(); ConfigurationElement config = mock(ConfigurationElement.class); ConfigurationElement nameConfig = mock(ConfigurationElement.class); ConfigurationElement redConfig = mock(ConfigurationElement.class); ConfigurationElement greenConfig = mock(ConfigurationElement.class); ConfigurationElement blueConfig = mock(ConfigurationElement.class); when(nameConfig.getValue()).thenReturn("test_name"); when(redConfig.getValue()).thenReturn("radiance_12"); when(greenConfig.getValue()).thenReturn("radiance_6"); when(blueConfig.getValue()).thenReturn("radiance_2"); when(config.getChild("name")).thenReturn(nameConfig); when(config.getChild("red")).thenReturn(redConfig); when(config.getChild("green")).thenReturn(greenConfig); when(config.getChild("blue")).thenReturn(blueConfig); when(config.getChild("alpha")).thenReturn(null); profile.configure(config); assertEquals("test_name", profile.getName()); assertEquals("", profile.getAlphaExpression()); assertEquals("radiance_2", profile.getBlueExpression()); assertEquals("radiance_12", profile.getRedExpression()); assertEquals("radiance_6", profile.getGreenExpression()); assertNull(profile.getPattern()); }