List of usage examples for org.apache.commons.configuration Configuration subset
Configuration subset(String prefix);
From source file:com.github.anba.es6draft.util.Resources.java
/** * Loads the configuration file.//from w ww . j a va 2 s . com */ public static Configuration loadConfiguration(Class<?> clazz) { TestConfiguration config = clazz.getAnnotation(TestConfiguration.class); String file = config.file(); String name = config.name(); try { PropertiesConfiguration properties = new PropertiesConfiguration(); // entries are mandatory unless an explicit default value was given properties.setThrowExceptionOnMissing(true); properties.getInterpolator().setParentInterpolator(MISSING_VAR); properties.load(resource(file), "UTF-8"); Configuration configuration = new CompositeConfiguration( Arrays.asList(new SystemConfiguration(), properties)); return configuration.subset(name); } catch (ConfigurationException | IOException e) { throw new RuntimeException(e); } catch (NoSuchElementException e) { throw e; } }
From source file:edu.kit.dama.mdm.tools.TransitionTypeHandlerFactory.java
/** * Factory a transition type handler for the provided transition type. The * factory will check in the according configuration section for the * configured handler. If no handler section exists, a * NullTransitionTypeHandler is returned. * * If a section for the transition type exists, the handler class is * obtained, checked and the handler is instantiated, configured and * returned. If the handler class is not set, a NullTransitionTypeHandler is * returned.. Otherwise, if a handler class is provided and any of these * previous steps fails, a ConfigurationException is thrown. * * @param pType The transition type for which the handler should be * returned.//from www.ja v a2s. c o m * * @return The transition type handler instance. * * @throws ConfigurationException if a handler section was found, but * instantiation or configuration of the handler has failed. */ public static AbstractTransitionTypeHandler factoryTransitionTypeHandler(TransitionType pType) throws ConfigurationException { LOGGER.debug("Trying to factory transition type handler for type '{}'", pType); Configuration subConfig = DataManagerSettings.getSingleton() .getSubConfiguration(DataManagerSettings.METADATA_MANAGEMENT_CONFIG_ROOT); if (subConfig == null) { //old datamanager.xml, no metadataManagement config node LOGGER.info( "No section '{}' found in datamanager.xml configuration file. Probably, transition type handlers have not been configured, yet. Returning NullTransitionTypeHandler.", DataManagerSettings.METADATA_MANAGEMENT_CONFIG_ROOT); return new NullTransitionTypeHandler(); } Configuration subset = subConfig.subset("transitionTypes." + pType.toString()); if (subset == null) { //no configuration found for te transition type...type not supported. LOGGER.info( "No sub-section for handler type '{}' found in datamanager.xml configuration file. Probably, the transition type handler has not been configured, yet. Returning NullTransitionTypeHandler.", pType); return new NullTransitionTypeHandler(); } try { String handlerClass = subset.getString("handlerClass"); if (handlerClass == null) { LOGGER.info( "No handler class defined for type '" + pType + "'. Returning NullTransitionTypeHandler."); return new NullTransitionTypeHandler(); } Class clazz = Class.forName(handlerClass); Object instance = clazz.getConstructor().newInstance(); ((IConfigurableAdapter) instance).configure(subset); return (AbstractTransitionTypeHandler) instance; } catch (ClassNotFoundException cnfe) { throw new ConfigurationException("Failed to locate transition handler class for type '" + pType + "'", cnfe); } catch (InstantiationException | IllegalAccessException | InvocationTargetException ie) { throw new ConfigurationException( "Failed to instantiate and configure transition handler for type '" + pType + "'", ie); } catch (NoSuchMethodException nsme) { throw new ConfigurationException( "Missing default constructor for transition handler class for type '" + pType + "'", nsme); } catch (ClassCastException cce) { throw new ConfigurationException( "Transition handler instance for type '" + pType + "' does not implement IConfigurableAdapter.", cce); } }
From source file:com.comcast.viper.flume2storm.connection.parameters.SimpleConnectionParametersFactory.java
/** * @see com.comcast.viper.flume2storm.connection.parameters.ConnectionParametersFactory#create(org.apache.commons.configuration.Configuration) *///ww w.j av a 2 s . c o m @Override public SimpleConnectionParameters create(Configuration config) throws F2SConfigurationException { return SimpleConnectionParameters.from(config.subset(CONFIG_BASE_NAME)); }
From source file:com.comcast.viper.flume2storm.connection.parameters.KryoNetConnectionParametersFactory.java
/** * @see com.comcast.viper.flume2storm.connection.parameters.ConnectionParametersFactory#create(org.apache.commons.configuration.Configuration) *//* w ww .j a v a 2 s.co m*/ @Override public KryoNetConnectionParameters create(Configuration config) throws F2SConfigurationException { return KryoNetConnectionParameters.from(config.subset(CONFIG_BASE_NAME)); }
From source file:com.linkedin.pinot.common.segment.fetcher.HttpsSegmentFetcher.java
@Override protected void initHttpClient(Configuration configs) { SSLContext sslContext = new ClientSSLContextGenerator(configs.subset(CommonConstants.PREFIX_OF_SSL_SUBSET)) .generate();/*w w w.j av a 2s.c om*/ _httpClient = new FileUploadDownloadClient(sslContext); }
From source file:com.cisco.oss.foundation.message.AbstractMessageProducer.java
private boolean isMonitoringEnabled() { Configuration configuration = ConfigurationFactory.getConfiguration(); Configuration subset = configuration.subset(producerName); boolean isMonitoringEnabled = subset.getBoolean("queue.isMonitoringEnabled", false); return isMonitoringEnabled; }
From source file:com.cisco.oss.foundation.message.AbstractMessageHandler.java
private boolean isMonitoringEnabled() { Configuration configuration = ConfigurationFactory.getConfiguration(); Configuration subset = configuration.subset(consumerName); boolean isMonitoringEnabled = subset.getBoolean("queue.isMonitoringEnabled", false); return isMonitoringEnabled; }
From source file:com.linkedin.pinot.routing.PercentageBasedRoutingTableSelector.java
public void init(Configuration configuration) { try {/*w w w .jav a2s . co m*/ Configuration tablesConfig = configuration.subset(TABLE_KEY); if (tablesConfig == null || tablesConfig.isEmpty()) { LOGGER.info("No specific table configuration. Using 0% LLC for all tables"); return; } ConfigurationMap cmap = new ConfigurationMap(tablesConfig); Set<Map.Entry<String, Integer>> mapEntrySet = cmap.entrySet(); for (Map.Entry<String, Integer> entry : mapEntrySet) { LOGGER.info("Using {} percent LLC routing for table {}", entry.getValue(), entry.getKey()); _percentMap.put(entry.getKey(), entry.getValue()); } } catch (Exception e) { LOGGER.warn("Could not parse get config for {}. Using no LLC routing", TABLE_KEY, e); } }
From source file:fr.mby.utils.spring.beans.factory.ProxywiredField.java
@Override public Configuration getConfigurationSubset(final Configuration allConfiguration) { return allConfiguration.subset(this.nodePath); }
From source file:ai.grakn.graql.internal.analytics.CommonOLAP.java
/** * Load <code>persistentProperties</code> and any hard coded fields from an apache config object for use by the * spark executor./*from w w w.j a va 2 s.c om*/ * * @param graph the tinker graph * @param configuration the apache config object containing the values */ public void loadState(final Graph graph, final Configuration configuration) { // load selected types configuration.subset(PREFIX_SELECTED_TYPE_KEY).getKeys().forEachRemaining( key -> selectedTypes.add(TypeId.of(configuration.getInt(PREFIX_SELECTED_TYPE_KEY + "." + key)))); // load user specified properties configuration.subset(PREFIX_PERSISTENT_PROPERTIES).getKeys().forEachRemaining(key -> persistentProperties .put(key, configuration.getProperty(PREFIX_PERSISTENT_PROPERTIES + "." + key))); }