Java Code Examples for org.apache.commons.configuration2.ConfigurationUtils

The following examples show how to use org.apache.commons.configuration2.ConfigurationUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: tinkerpop   Source File: ConnectedComponentVertexProgram.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void loadState(final Graph graph, final Configuration config) {
    configuration = new BaseConfiguration();
    if (config != null) {
        ConfigurationUtils.copy(config, configuration);
    }

    if (configuration.containsKey(EDGE_TRAVERSAL)) {
        this.edgeTraversal = PureTraversal.loadState(configuration, EDGE_TRAVERSAL, graph);
        this.scope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
    }

    scopes = new HashSet<>(Collections.singletonList(scope));

    this.property = configuration.getString(PROPERTY, COMPONENT);

    this.haltedTraversers = TraversalVertexProgram.loadHaltedTraversers(configuration);
    this.haltedTraversersIndex = new IndexedTraverserSet<>(v -> v);
    for (final Traverser.Admin<Vertex> traverser : this.haltedTraversers) {
        this.haltedTraversersIndex.add(traverser.split());
    }
}
 
Example 2
/**
 * Creates a new, uninitialized instance of the builder class managed by
 * this provider. This implementation determines the builder class to be
 * used by delegating to {@code determineBuilderClass()}. It then calls the
 * constructor expecting the configuration class, the map with properties,
 * and the<em>allowFailOnInit</em> flag.
 *
 * @param decl the current {@code ConfigurationDeclaration}
 * @param params initialization parameters for the new builder object
 * @return the newly created builder instance
 * @throws Exception if an error occurs
 */
protected BasicConfigurationBuilder<? extends Configuration> createBuilder(
        final ConfigurationDeclaration decl, final Collection<BuilderParameters> params)
        throws Exception
{
    final Class<?> bldCls =
            ConfigurationUtils.loadClass(determineBuilderClass(decl));
    final Class<?> configCls =
            ConfigurationUtils.loadClass(determineConfigurationClass(decl,
                    params));
    final Constructor<?> ctor = bldCls.getConstructor(CTOR_PARAM_TYPES);
    // ? extends Configuration is the minimum constraint
    @SuppressWarnings("unchecked")
    final
    BasicConfigurationBuilder<? extends Configuration> builder =
            (BasicConfigurationBuilder<? extends Configuration>) ctor
                    .newInstance(configCls, null, isAllowFailOnInit(decl));
    return builder;
}
 
Example 3
/**
 * Creates a configuration which wraps the specified builder.
 *
 * @param builder the builder
 * @return the wrapping configuration
 */
// It is safe to disable any type checks because we manually determine
// the interface class to be passed to BuilderConfigurationWrapperFactory
@SuppressWarnings({
        "unchecked", "rawtypes"
})
private Configuration createWrapperConfiguration(
        final ConfigurationBuilder builder)
{
    final Class<?> configClass =
            ConfigurationUtils.loadClassNoEx(getConfigurationClass());
    final Class ifcClass =
            HierarchicalConfiguration.class.isAssignableFrom(configClass) ? HierarchicalConfiguration.class
                    : Configuration.class;
    return (Configuration) BuilderConfigurationWrapperFactory
            .createBuilderConfigurationWrapper(ifcClass, builder,
                    EventSourceSupport.BUILDER);
}
 
Example 4
/**
 * Creates a map with parameters for a new managed configuration builder.
 * This method merges the basic parameters set for this builder with the
 * specific parameters object for managed builders (if provided).
 *
 * @param params the parameters of this builder
 * @param multiParams the parameters object for this builder
 * @return the parameters for a new managed builder
 */
private static Map<String, Object> createManagedBuilderParameters(
        final Map<String, Object> params,
        final MultiFileBuilderParametersImpl multiParams)
{
    final Map<String, Object> newParams = new HashMap<>(params);
    newParams.remove(KEY_INTERPOLATOR);
    final BuilderParameters managedBuilderParameters =
            multiParams.getManagedBuilderParameters();
    if (managedBuilderParameters != null)
    {
        // clone parameters as they are applied to multiple builders
        final BuilderParameters copy =
                (BuilderParameters) ConfigurationUtils
                        .cloneIfPossible(managedBuilderParameters);
        newParams.putAll(copy.getParameters());
    }
    return newParams;
}
 
Example 5
Source Project: DataflowTemplates   Source File: App.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    final Logger logger = LoggerFactory.getLogger(App.class);

    // Printing the information about the bindings for SLF4J:
    Configuration config = getConnectorConfiguration(args);
    final StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
    System.out.println("Logger Binding: " + binder.getLoggerFactory());
    System.out.println(binder.getLoggerFactoryClassStr());

    String dbPassword = config.getString("databasePassword");
    config.clearProperty("databasePassword");
    logger.info("Configuration for program (with DB password hidden) is: \n{}",
        ConfigurationUtils.toString(config));
    config.setProperty("databasePassword", dbPassword);

    logger.info("GOOGLE_APPLICATION_CREDENTIALS: {}",
        System.getenv("GOOGLE_APPLICATION_CREDENTIALS"));

// Properties to be passed directly to Debezium
ImmutableConfiguration debeziumConfig = config.immutableSubset("debezium");

startSender(
    config.getString("databaseName"),
    config.getString("databaseUsername"),
    config.getString("databasePassword"),
    config.getString("databaseAddress"),
    config.getString("databasePort", "3306"), // MySQL default port is 3306
    config.getString("gcpProject"),
    config.getString("gcpPubsubTopicPrefix"),
    config.getString("offsetStorageFile", DEFAULT_OFFSET_STORAGE_FILE),
    config.getString("databaseHistoryFile", DEFAULT_DATABASE_HISTORY_FILE),
    config.getBoolean("inMemoryOffsetStorage", false),
    config.getBoolean("singleTopicMode", false),
    config.getString("whitelistedTables"),
    config.getString("databaseManagementSystem", DEFAULT_RDBMS),
    debeziumConfig);
}
 
Example 6
Source Project: obevo   Source File: PackageMetadataReader.java    License: Apache License 2.0 5 votes vote down vote up
private ImmutableHierarchicalConfiguration getConfig(String configContent) {
    if (configContent == null) {
        return new BaseHierarchicalConfiguration();
    }

    Properties props = new Properties();
    try {
        props.load(new StringReader(configContent));
        return ConfigurationUtils.convertToHierarchical(ConfigurationConverter.getConfiguration(props));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 7
Source Project: tinkerpop   Source File: HadoopPools.java    License: Apache License 2.0 5 votes vote down vote up
public static GryoPool getGryoPool() {
    if (!INITIALIZED) {
        final Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("tinkerpop", true);
        HadoopGraph.LOGGER.warn("The " + HadoopPools.class.getSimpleName() + " has not been initialized, using system properties configuration: " + ConfigurationUtils.toString(configuration));
        initialize(configuration);
    }
    return GRYO_POOL;
}
 
Example 8
Source Project: tinkerpop   Source File: GraphFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static org.apache.commons.configuration2.Configuration getConfiguration(final File configurationFile) {
    if (!configurationFile.isFile())
        throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));

    try {
        final String fileName = configurationFile.getName();
        final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);

        final Configuration conf;
        final Configurations configs = new Configurations();

        switch (fileExtension) {
            case "yml":
            case "yaml":
                final Parameters params = new Parameters();
                final FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
                        new FileBasedConfigurationBuilder<FileBasedConfiguration>(YAMLConfiguration.class).
                                configure(params.fileBased().setFile(configurationFile));

                final org.apache.commons.configuration2.Configuration copy = new org.apache.commons.configuration2.BaseConfiguration();
                ConfigurationUtils.copy(builder.configure(params.fileBased().setFile(configurationFile)).getConfiguration(), copy);
                conf = copy;
                break;
            case "xml":
                conf = configs.xml(configurationFile);
                break;
            default:
                conf = configs.properties(configurationFile);
        }
        return conf;
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
    }
}
 
Example 9
Source Project: tinkerpop   Source File: ConnectedComponentVertexProgram.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void storeState(final Configuration config) {
    VertexProgram.super.storeState(config);
    if (configuration != null) {
        ConfigurationUtils.copy(configuration, config);
    }
}
 
Example 10
Source Project: tinkerpop   Source File: GraphComputerTest.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public VertexProgramQ create(final Graph graph) {
    if (graph != null) {
        ConfigurationUtils.append(graph.configuration().subset(VERTEX_PROGRAM_Q_CFG_PREFIX), configuration);
    }
    return (VertexProgramQ) VertexProgram.createVertexProgram(graph, configuration);
}
 
Example 11
Source Project: tinkerpop   Source File: GraphComputerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void storeState(final Configuration config) {
    VertexProgram.super.storeState(config);
    if (configuration != null) {
        ConfigurationUtils.copy(configuration, config);
    }
}
 
Example 12
Source Project: tinkerpop   Source File: GraphComputerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void loadState(final Graph graph, final Configuration config) {
    configuration = new BaseConfiguration();
    if (config != null) {
        ConfigurationUtils.copy(config, configuration);
    }
    propertyKey = configuration.getString(PROPERTY_CFG_KEY);
    traverserRequirements = configuration.getBoolean(USE_TRAVERSER_REQUIREMENTS_CFG_KEY, true)
            ? Collections.singleton(TraverserRequirement.PATH) : Collections.emptySet();
    elementComputeKeys.add(VertexComputeKey.of(propertyKey, false));
}
 
Example 13
Source Project: tinkerpop   Source File: GraphComputerTest.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public VertexProgramR create(final Graph graph) {
    if (graph != null) {
        ConfigurationUtils.append(graph.configuration().subset(SIMPLE_VERTEX_PROGRAM_CFG_PREFIX), configuration);
    }
    return (VertexProgramR) VertexProgram.createVertexProgram(graph, configuration);
}
 
Example 14
/**
 * Registers the available event listeners at the given object. This method
 * is called for each result object created by the builder.
 *
 * @param obj the object to initialize
 */
private void registerEventListeners(final T obj)
{
    final EventSource evSrc = ConfigurationUtils.asEventSource(obj, true);
    for (final EventListenerRegistrationData<?> regData : eventListeners
            .getRegistrations())
    {
        registerListener(evSrc, regData);
    }
}
 
Example 15
/**
 * Removes all available event listeners from the given result object. This
 * method is called when the result of this builder is reset. Then the old
 * managed configuration should no longer generate events.
 *
 * @param obj the affected result object
 */
private void removeEventListeners(final T obj)
{
    final EventSource evSrc = ConfigurationUtils.asEventSource(obj, true);
    for (final EventListenerRegistrationData<?> regData : eventListeners
            .getRegistrations())
    {
        removeListener(evSrc, regData);
    }
}
 
Example 16
/**
 * {@inheritDoc} This implementation also tries to clone the parameters
 * object for managed builders if possible.
 */
@Override
public MultiFileBuilderParametersImpl clone()
{
    final MultiFileBuilderParametersImpl copy =
            (MultiFileBuilderParametersImpl) super.clone();
    copy.setManagedBuilderParameters((BuilderParameters) ConfigurationUtils
            .cloneIfPossible(getManagedBuilderParameters()));
    return copy;
}
 
Example 17
/**
 * {@inheritDoc} This implementation also clones the parameters object for
 * the definition builder if possible.
 */
@Override
public CombinedBuilderParametersImpl clone()
{
    final CombinedBuilderParametersImpl copy =
            (CombinedBuilderParametersImpl) super.clone();
    copy.setDefinitionBuilderParameters((BuilderParameters) ConfigurationUtils
            .cloneIfPossible(getDefinitionBuilderParameters()));
    return copy;
}
 
Example 18
/**
 * Creates an instance of a parameter class using reflection.
 *
 * @param paramcls the parameter class
 * @return the newly created instance
 * @throws Exception if an error occurs
 */
private static BuilderParameters createParameterObject(final String paramcls)
        throws Exception
{
    final Class<?> cls = ConfigurationUtils.loadClass(paramcls);
    final BuilderParameters p = (BuilderParameters) cls.newInstance();
    return p;
}
 
Example 19
Source Project: spoofax   Source File: AConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
protected HierarchicalConfiguration<ImmutableNode> cloneConfiguration(IConfig config) {
    // Clone configuration.
    final IConfig iconfig = (IConfig) config;
    final HierarchicalConfiguration<ImmutableNode> apacheConfig = iconfig.getConfig();
    final Configuration clonedConfig = ConfigurationUtils.cloneConfiguration(apacheConfig);
    @SuppressWarnings("unchecked") final HierarchicalConfiguration<ImmutableNode> clonedHierachicalConfig =
            (HierarchicalConfiguration<ImmutableNode>) clonedConfig;
    return clonedHierachicalConfig;
}
 
Example 20
Source Project: batfish   Source File: BaseSettings.java    License: Apache License 2.0 4 votes vote down vote up
public ImmutableConfiguration getImmutableConfiguration() {
  return ConfigurationUtils.unmodifiableConfiguration(_config);
}
 
Example 21
Source Project: fluo   Source File: SimpleConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return ConfigurationUtils.toString(internalConfig);
}
 
Example 22
/**
 * Handles a method invocation on the {@code EventSource} interface.
 * This method evaluates the current {@code EventSourceSupport} object
 * in order to find the appropriate target for the invocation.
 *
 * @param method the method to be invoked
 * @param args method arguments
 * @return the return value of the method
 * @throws Exception if an error occurs
 */
private Object handleEventSourceInvocation(final Method method, final Object... args)
        throws Exception
{
    final Object target =
            EventSourceSupport.DUMMY == eventSourceSupport ? ConfigurationUtils
                    .asEventSource(this, true) : builder;
    return method.invoke(target, args);
}
 
Example 23
Source Project: batfish   Source File: BaseSettings.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Initialize settings from an existing configuration
 *
 * @param config {@link Configuration} containing the desired settings
 */
public BaseSettings(Configuration config) {
  _options = new Options();
  _config = ConfigurationUtils.cloneConfiguration(config);
}
 
Example 24
Source Project: batfish   Source File: IncrementalDataPlaneSettings.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create new settings, initialize with defaults, but also copy over settings from {@code
 * configSource}
 *
 * @param configSource the configuration options to override the defaults
 */
public IncrementalDataPlaneSettings(ImmutableConfiguration configSource) {
  this();
  ConfigurationUtils.copy(configSource, _config);
}
 
Example 25
/**
 * Returns an {@code EventSource} for the current result object. If there is
 * no current result or if it does not extend {@code EventSource}, a dummy
 * event source is returned.
 *
 * @return the {@code EventSource} for the current result object
 */
private EventSource fetchEventSource()
{
    return ConfigurationUtils.asEventSource(result, true);
}