/** * Creates a configured builder for a file-based configuration of the * specified type. * * @param configClass the configuration class * @param params the parameters object for configuring the builder * @param <T> the type of the configuration to be constructed * @return the newly created builder */ private <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> createFileBasedBuilder( final Class<T> configClass, final FileBasedBuilderParameters params) { return new FileBasedConfigurationBuilder<>(configClass) .configure(params); }
/** * {@inheritDoc} This implementation evaluates the file name pattern using * the configured {@code ConfigurationInterpolator}. If this file has * already been loaded, the corresponding builder is accessed. Otherwise, a * new builder is created for loading this configuration file. */ @Override public T getConfiguration() throws ConfigurationException { return getManagedBuilder().getConfiguration(); }
/** * {@inheritDoc} This implementation checks whether an auto-safe operation * should be performed. This is the case if the event indicates that an * update of the configuration has been performed and currently no load * operation is in progress. */ @Override public void onEvent(final ConfigurationEvent event) { if (autoSaveRequired(event)) { try { builder.save(); } catch (final ConfigurationException ce) { log.warn("Auto save failed!", ce); } } }
public XMLConfiguration loadConfig(String configFile) throws ConfigurationException { Parameters params = new Parameters(); FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class) .configure(params.xml() .setFileName(configFile)); XMLConfiguration xmlConfig = builder.getConfiguration(); return xmlConfig; }
/** * Creates a builder for a managed configuration. This method is called * whenever a configuration for a file name is requested which has not yet * been loaded. The passed in map with parameters is populated from this * builder's configuration (i.e. the basic parameters plus the optional * parameters for managed builders). This base implementation creates a * standard builder for file-based configurations. Derived classes may * override it to create special purpose builders. * * @param fileName the name of the file to be loaded * @param params a map with initialization parameters for the new builder * @return the newly created builder instance * @throws ConfigurationException if an error occurs */ protected FileBasedConfigurationBuilder<T> createManagedBuilder( final String fileName, final Map<String, Object> params) throws ConfigurationException { return new FileBasedConfigurationBuilder<>(getResultClass(), params, isAllowFailOnInit()); }
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new Configurations() .propertiesBuilder(solrConfigDir); PropertiesConfiguration config = builder.getConfiguration(); config.setProperty("workflow-start-date", new DCDate(oldestDate)); builder.save(); } catch (ConfigurationException e) { log.error("Error while storing workflow start date", e);
/** * {@inheritDoc} This method is overridden here to change the result type. */ @Override public ReloadingFileBasedConfigurationBuilder<T> configure( final BuilderParameters... params) { super.configure(params); return this; }
private static FileBasedConfiguration createConfiguration(Reader reader) throws ConfigurationException { if (reader == null) { throw new NullPointerException("reader: null"); } FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(XMLConfiguration.class) .configure(new Parameters().xml()); FileBasedConfiguration fileBasedConfiguration = builder.getConfiguration(); FileHandler handler = new FileHandler(fileBasedConfiguration); handler.load(reader); return fileBasedConfiguration; }
private BasicConfigurationBuilder<? extends Configuration> createConfiguration() { BasicConfigurationBuilder<? extends Configuration> builder; switch (configurationType) { case XML: builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class); break; case SYSTEM: builder = new BasicConfigurationBuilder<>(SystemConfiguration.class); break; default: builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class); } return builder; }
private void configureFileBuilder(Enumeration<URL> urlResources) { Parameters params = new Parameters(); while (urlResources.hasMoreElements()) { BasicConfigurationBuilder<? extends Configuration> builder = createConfiguration(); URL url = urlResources.nextElement(); ((FileBasedConfigurationBuilder<?>) builder).configure(params.fileBased().setURL(url)); try { configurations.add(builder.getConfiguration()); } catch (ConfigurationException e) { logger.warning(message.failOnCreateApacheConfiguration(e.getMessage())); } } }
private HierarchicalConfiguration<ImmutableNode> loadPropertiesFromUrl(FileObject file) { try { return new FileBasedConfigurationBuilder<>(FixedYAMLConfiguration.class) .configure(new Parameters().hierarchical().setURL(file.getURLDa())) .getConfiguration(); } catch (ConfigurationException e) { throw new DeployerRuntimeException(e); } }
/** * Creates a {@code XMLConfiguration} instance from the content of the given * URL. This is a convenience method which can be used if no builder is * needed for managing the configuration object. (Although, behind the * scenes a builder is created). * * @param url the URL to be loaded * @return a {@code XMLConfiguration} object initialized from this file * @throws ConfigurationException if an error occurred when loading the * configuration */ public XMLConfiguration xml(final URL url) throws ConfigurationException { return xmlBuilder(url).getConfiguration(); }
/** * Creates a default builder for the definition configuration and * initializes it with a parameters object. This method is called if no * definition builder is defined in this builder's parameters. This * implementation creates a default file-based builder which produces an * {@code XMLConfiguration}; it expects a corresponding file specification. * Note: This method is called in a synchronized block. * * @param builderParams the parameters object for the builder * @return the standard builder for the definition configuration */ protected ConfigurationBuilder<? extends HierarchicalConfiguration<?>> createXMLDefinitionBuilder( final BuilderParameters builderParams) { return new FileBasedConfigurationBuilder<>( XMLConfiguration.class).configure(builderParams); }
config = builder; } else { config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class); config.configure(params);
private HierarchicalConfiguration<ImmutableNode> loadPropertiesFromUrl(FileObject file) { try { return new FileBasedConfigurationBuilder<>(FixedYAMLConfiguration.class) .configure(new Parameters().hierarchical().setURL(file.getURLDa())) .getConfiguration(); } catch (ConfigurationException e) { throw new DeployerRuntimeException(e); } }
/** * Creates a {@code INIConfiguration} instance from the content of the file * identified by the given path. This is a convenience method which can be * used if no builder is needed for managing the configuration object. * (Although, behind the scenes a builder is created). * * @param path the path to the file to be loaded * @return a {@code INIConfiguration} object initialized from this file * @throws ConfigurationException if an error occurred when loading the * configuration */ public INIConfiguration ini(final String path) throws ConfigurationException { return iniBuilder(path).getConfiguration(); }
private static FileBasedConfiguration createPropertiesConfiguration(Reader reader) throws ConfigurationException, IOException { if (reader == null) { throw new NullPointerException("reader: null"); } FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters() .properties() .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); FileBasedConfiguration config = builder.getConfiguration(); config.read(reader); return config; }
/** * Creates a {@code INIConfiguration} instance from the content of the given * file. This is a convenience method which can be used if no builder is * needed for managing the configuration object. (Although, behind the * scenes a builder is created). * * @param file the file to be loaded * @return a {@code INIConfiguration} object initialized from this file * @throws ConfigurationException if an error occurred when loading the * configuration */ public INIConfiguration ini(final File file) throws ConfigurationException { return iniBuilder(file).getConfiguration(); }