/** * 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; }
public String getApplicationId() { return moduleContext.getRuntimeConfig().getApplicationId(); }
/** * Gets the application context ID uses as prefix in a number of application configuration settings. * The context ID is configured using the system property "ceres.context". If this property is not set, * the string "beam" is used. * * @return The application context ID. * * @since BEAM 4.10 */ public static String getApplicationContextId() { String contextId = null; if (RuntimeContext.getModuleContext() != null) { contextId = RuntimeContext.getModuleContext().getRuntimeConfig().getContextId(); } if (contextId == null) { contextId = System.getProperty("ceres.context", "beam"); } return contextId; }
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; }
@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); } }
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 void discardUnusedMetadata(final Product product) { if (RuntimeContext.getModuleContext() != null) { final String dicardUnusedMetadata = RuntimeContext.getModuleContext().getRuntimeConfig(). getContextProperty("discard.unused.metadata"); if ("true".equalsIgnoreCase(dicardUnusedMetadata)) { removeUnusedMetadata(product.getMetadataRoot()); } } }
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);
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); } } }
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); } }
public static String getDefaultVectorDataNodeName() { return VisatActivator.getInstance().getModuleContext().getRuntimeConfig().getContextProperty(KEY_VECTOR_DATA_INITIAL_NAME, "geometry"); }
public static void transferConnectionData(PropertyMap propertyMap, ConnectionConfigData connectionConfigData) { ProxyConfig proxyConfig = new ProxyConfig(); connectionConfigData.setProxyConfig(proxyConfig); connectionConfigData.setRepositoryUrl(System.getProperty(SYS_KEY_BEAM_REPOSITORY_URL, "")); connectionConfigData.setProxyUsed(propertyMap.getPropertyBool(KEY_BEAM_REPOSITORY_PROXY_USED, false)); proxyConfig.setHost(propertyMap.getPropertyString(KEY_BEAM_REPOSITORY_PROXY_HOST)); proxyConfig.setPort(propertyMap.getPropertyInt(KEY_BEAM_REPOSITORY_PROXY_PORT)); proxyConfig.setAuthorizationUsed(propertyMap.getPropertyBool(KEY_BEAM_REPOSITORY_PROXY_AUTH_USED)); proxyConfig.setUsername(propertyMap.getPropertyString(KEY_BEAM_REPOSITORY_PROXY_USERNAME)); proxyConfig.setScrambledPassword(propertyMap.getPropertyString(KEY_BEAM_REPOSITORY_PROXY_PASSWORD)); } }
private static Module getModule(String symbolicName) { final Module[] modules = VisatActivator.getInstance().getModuleContext().getModules(); for (Module module : modules) { if (module.getSymbolicName().equals(symbolicName)) { return module; } } return null; } }
@Override public void start(ModuleContext moduleContext) throws CoreException { BeamCoreActivator.moduleContext = moduleContext; SystemUtils.init3rdPartyLibs(moduleContext.getModule().getClassLoader()); registerRGBProfiles(moduleContext); registerGeotoolsServices(); }
public static void transferConnectionData(ConnectionConfigData connectionConfigData, PropertyMap propertyMap) { ProxyConfig proxyConfig = connectionConfigData.getProxyConfig(); propertyMap.setPropertyBool(KEY_BEAM_REPOSITORY_PROXY_USED, connectionConfigData.isProxyUsed()); propertyMap.setPropertyString(KEY_BEAM_REPOSITORY_PROXY_HOST, proxyConfig.getHost()); propertyMap.setPropertyInt(KEY_BEAM_REPOSITORY_PROXY_PORT, proxyConfig.getPort()); propertyMap.setPropertyBool(KEY_BEAM_REPOSITORY_PROXY_AUTH_USED, proxyConfig.isAuthorizationUsed()); propertyMap.setPropertyString(KEY_BEAM_REPOSITORY_PROXY_USERNAME, proxyConfig.getUsername()); propertyMap.setPropertyString(KEY_BEAM_REPOSITORY_PROXY_PASSWORD, proxyConfig.getScrambledPassword()); }
static int compareVersions(String localVersion, String remoteVersion) { if (localVersion.startsWith(VERSION_PREFIX) && remoteVersion.startsWith(VERSION_PREFIX)) { Version v1 = Version.parseVersion(localVersion.substring(VERSION_PREFIX.length())); Version v2 = Version.parseVersion(remoteVersion.substring(VERSION_PREFIX.length())); return v1.compareTo(v2); } return localVersion.compareTo(remoteVersion); }
private URI getLocalDataSourcesUri() throws URISyntaxException { URL url = null; Module helpModule = getModule("beam-help"); if (helpModule != null) { url = helpModule.getResource("doc/help/general/BeamDataSources.html"); } if (url != null) { return url.toURI(); } else { return null; } }
public static void discardUnusedMetadata(final Product product) { final String dicardUnusedMetadata = RuntimeContext.getModuleContext().getRuntimeConfig(). getContextProperty("discard.unused.metadata"); if (dicardUnusedMetadata.equalsIgnoreCase("true")) { removeUnusedMetadata(AbstractMetadata.getOriginalProductMetadata(product)); } }
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"); } } }