org.apache.commons.configuration2.builder.fluent.Parameters.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.6k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中org.apache.commons.configuration2.builder.fluent.Parameters.<init>()方法的一些代码示例,展示了Parameters.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parameters.<init>()方法的具体详情如下:
包路径:org.apache.commons.configuration2.builder.fluent.Parameters
类名称:Parameters
方法名:<init>

Parameters.<init>介绍

[英]Creates a new instance of Parameters. A new, uninitialized DefaultParametersManager is created.
[中]创建参数的新实例。将创建一个未初始化的新DefaultParametersManager。

代码示例

代码示例来源:origin: org.apache.commons/commons-configuration2

/**
 * Creates a new instance of {@code Configurations} and initializes it with
 * the specified {@code Parameters} object.
 *
 * @param params the {@code Parameters} (may be <b>null</b>, then a default
 *        instance is created)
 */
public Configurations(final Parameters params)
{
  parameters = (params != null) ? params : new Parameters();
}

代码示例来源:origin: apache/nifi

@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
  final String config = context.getProperty(CONFIGURATION_FILE).evaluateAttributeExpressions().getValue();
  final FileBasedBuilderParameters params = new Parameters().fileBased().setFile(new File(config));
  this.builder = new ReloadingFileBasedConfigurationBuilder<>(resultClass).configure(params);
  builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST,
    new EventListener<ConfigurationBuilderEvent>() {
      @Override
      public void onEvent(ConfigurationBuilderEvent event) {
        if (builder.getReloadingController().checkForReloading(null)) {
          getLogger().debug("Reloading " + config);
        }
      }
    });
  try {
    // Try getting configuration to see if there is any issue, for example wrong file format.
    // Then throw InitializationException to keep this service in 'Enabling' state.
    builder.getConfiguration();
  } catch (ConfigurationException e) {
    throw new InitializationException(e);
  }
}

代码示例来源:origin: goldmansachs/obevo

public static DbDataComparisonConfig createFromProperties(String path) {
  try {
    URL url = DbDataComparisonConfigFactory.class.getClassLoader().getResource(path);
    if (url == null) {
      url = new File(path).toURI().toURL();
    }
    if (url == null) {
      throw new IllegalArgumentException("Could not find resource or file at path: " + path);
    }
    return createFromProperties(new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(new Parameters().properties()
        .setURL(url)
        .setListDelimiterHandler(new LegacyListDelimiterHandler(','))
    ).getConfiguration());
  } catch (ConfigurationException e) {
    throw new RuntimeException(e);
  } catch (MalformedURLException e) {
    throw new IllegalArgumentException("Could not find resource or file at path: " + path, e);
  }
}

代码示例来源:origin: com.goldmansachs.obevo/obevo-db

public static DbDataComparisonConfig createFromProperties(String path) {
  try {
    URL url = DbDataComparisonConfigFactory.class.getClassLoader().getResource(path);
    if (url == null) {
      url = new File(path).toURI().toURL();
    }
    if (url == null) {
      throw new IllegalArgumentException("Could not find resource or file at path: " + path);
    }
    return createFromProperties(new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(new Parameters().properties()
        .setURL(url)
        .setListDelimiterHandler(new LegacyListDelimiterHandler(','))
    ).getConfiguration());
  } catch (ConfigurationException e) {
    throw new RuntimeException(e);
  } catch (MalformedURLException e) {
    throw new IllegalArgumentException("Could not find resource or file at path: " + path, e);
  }
}

代码示例来源:origin: demoiselle/framework

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()));
    }
  }
}

代码示例来源:origin: com.cerner.beadledom/beadledom-configuration

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;
}

代码示例来源:origin: de.julielab/julielab-topic-modeling

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;
}

代码示例来源:origin: com.cerner.beadledom/beadledom-configuration

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;
}

代码示例来源:origin: org.opencadc/cadc-web-util

public ApplicationConfiguration(final String filePath) {
  final CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new MergeCombiner());
  // Prefer System properties.
  combinedConfiguration.addConfiguration(new SystemConfiguration());
  final Parameters parameters = new Parameters();
  final FileBasedConfigurationBuilder builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(parameters.properties()
    .setFileName(filePath));
  try {
    combinedConfiguration.addConfiguration((Configuration) builder.getConfiguration());
  } catch (ConfigurationException var5) {
    LOGGER.warn(String.format("No configuration found at %s.\nUsing defaults.", filePath));
  }
  this.configuration = combinedConfiguration;
}

代码示例来源:origin: goldmansachs/obevo

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);
  }
}

代码示例来源:origin: com.goldmansachs.obevo/obevo-core

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);
  }
}

代码示例来源:origin: de.julielab/jssf-commons

public ExternalToolService() throws ConfigurationException {
  ClasspathResource resource = new ClasspathResource(ExternalToolConstants.EXTERNAL_TOOL_VERSIONS_FILE);
  Parameters params = new Parameters();
  FileBasedConfigurationBuilder<JSONConfiguration> configBuilder =
      new FileBasedConfigurationBuilder<>(JSONConfiguration.class).configure(params.hierarchical()
          .setLocationStrategy(new ClasspathLocationStrategy())
          .setFileName(ExternalToolConstants.EXTERNAL_TOOL_VERSIONS_FILE));
  externalToolsConfiguration = configBuilder.getConfiguration();
}

代码示例来源:origin: qaprosoft/carina

private AliceRecognition() {
  try {
    CombinedConfiguration config = new CombinedConfiguration(new MergeCombiner());
    config.addConfiguration(new SystemConfiguration());
    config.addConfiguration(new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
        .configure(new Parameters().properties().setFileName(ALICE_PROPERTIES)).getConfiguration());
    this.enabled = config.getBoolean(ALICE_ENABLED, false);
    String url = config.getString(ALICE_SERVICE_URL, null);
    String accessToken = config.getString(ALICE_ACCESS_TOKEN, null);
    String command = config.getString(ALICE_COMMAND, null);
    if (enabled && !StringUtils.isEmpty(url) && !StringUtils.isEmpty(accessToken)) {
      this.client = new AliceClient(url, command);
      this.client.setAuthToken(accessToken);
      this.enabled = this.client.isAvailable();
    }
  } catch (Exception e) {
    LOGGER.error("Unable to initialize Alice: " + e.getMessage(), e);
  }
};

代码示例来源:origin: goldmansachs/obevo

@Test
  public void yamlTest() throws Exception {
    ImmutableHierarchicalConfiguration configuration = new FileBasedConfigurationBuilder<>(FixedYAMLConfiguration.class)
        .configure(new Parameters().hierarchical()
            .setFile(new File("./src/test/resources/DbEnvironmentXmlEnricher/system-config.yaml"))
//                        .setFile(new File("./src/test/resources/DbEnvironmentXmlEnricher/system-config.xml"))
        ).getConfiguration();
    System.out.println(configuration);
  }

代码示例来源:origin: de.julielab/julielab-java-utilities

/**
 * Loads the Apache Commons Configuration2 {@link XMLConfiguration} from the given file. By default,
 * the {@link XPathExpressionEngine} is set.
 * @param configurationFile
 * @return
 * @throws ConfigurationException
 */
public static XMLConfiguration loadXmlConfiguration(File configurationFile) throws ConfigurationException {
  try {
    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<XMLConfiguration> configBuilder =
        new FileBasedConfigurationBuilder<>(XMLConfiguration.class).configure(params
            .xml()
            .setExpressionEngine(new XPathExpressionEngine())
            .setFile(configurationFile));
    return configBuilder.getConfiguration();
  } catch (org.apache.commons.configuration2.ex.ConfigurationException e) {
    throw new ConfigurationException(e);
  }
}

代码示例来源:origin: goldmansachs/obevo

@Test
  public void convert() throws Exception {
    XMLConfiguration configuration = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
        .configure(new Parameters().hierarchical()
            .setFile(new File("./src/test/resources/DbEnvironmentXmlEnricher/system-config.xml"))
        ).getConfiguration();

    Map<String, Object> myMap = constructMap(configuration.getNodeModel().getNodeHandler().getRootNode());

    FixedYAMLConfiguration yamlConfiguration = new FixedYAMLConfiguration(configuration);
    StringWriter sw = new StringWriter();
//        yamlConfiguration.write();
    DumperOptions dumperOptions = new DumperOptions();
//        dumperOptions.setPrettyFlow(true);
    dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(dumperOptions);
    yaml.dump(myMap, sw);

//        yamlConfiguration.dump(sw, new DumperOptions());
    System.out.println(sw.toString());
  }

代码示例来源:origin: Wikia/selenium-tests

/**
 * method used to get credentials from configuration xml
 */
public static String getValue(File file, String key) {
 if (!file.exists() || file.isDirectory()) {
  throw new ConfigurationRuntimeException("Cannot find a file with credentials");
 }
 try {
  Parameters params = new Parameters();
  FileBasedConfigurationBuilder<XMLConfiguration> builder =
      new FileBasedConfigurationBuilder<>(XMLConfiguration.class).configure(params.fileBased().setFile(file));
  org.apache.commons.configuration2.Configuration config = builder.getConfiguration();
  return config.getString(key);
 } catch (ConfigurationException e) {
  throw new ConfigurationRuntimeException(e);
 }
}

代码示例来源:origin: goldmansachs/obevo

public void execute(DbFileMergerArgs args) {
  Configuration config;
  try {
    config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
        .configure(new Parameters().properties()
            .setFile(args.getDbMergeConfigFile())
            .setListDelimiterHandler(new LegacyListDelimiterHandler(','))
        ).getConfiguration();
  } catch (ConfigurationException e) {
    throw new RuntimeException(e);
  }
  RichIterable<DbMergeInfo> dbMergeInfos = DbMergeInfo.parseFromProperties(config);
  RichIterable<TableSyncSide> tableSyncSides = dbMergeInfos.collect(new Function<DbMergeInfo, TableSyncSide>() {
    @Override
    public TableSyncSide valueOf(DbMergeInfo dbMergeInfo) {
      DataSource ds = ds(dbMergeInfo.getDriverClassName(), dbMergeInfo.getUrl(), dbMergeInfo.getUsername(),
          dbMergeInfo.getPassword());
      return new TableSyncSide(ds, PhysicalSchema.parseFromString(dbMergeInfo.getPhysicalSchema()));
    }
  });
  this.syncSchemaTables(DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType")), tableSyncSides, args.getOutputDir());
}

代码示例来源:origin: com.goldmansachs.obevo/obevo-db

public void execute(DbFileMergerArgs args) {
  PropertiesConfiguration config;
  RichIterable<DbMergeInfo> dbNameLocationPairs;
  try {
    config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
        .configure(new Parameters().properties()
            .setFile(args.getDbMergeConfigFile())
            .setListDelimiterHandler(new LegacyListDelimiterHandler(','))
        )
        .getConfiguration();
    dbNameLocationPairs = DbMergeInfo.parseFromProperties(config);
  } catch (Exception e) {
    throw new DeployerRuntimeException("Exception reading configs from file " + args.getDbMergeConfigFile(), e);
  }
  DbPlatform dialect = DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType"));
  this.generateDiffs(dialect, dbNameLocationPairs, args.getOutputDir());
}

代码示例来源:origin: goldmansachs/obevo

public void execute(DbFileMergerArgs args) {
  PropertiesConfiguration config;
  RichIterable<DbMergeInfo> dbNameLocationPairs;
  try {
    config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
        .configure(new Parameters().properties()
            .setFile(args.getDbMergeConfigFile())
            .setListDelimiterHandler(new LegacyListDelimiterHandler(','))
        )
        .getConfiguration();
    dbNameLocationPairs = DbMergeInfo.parseFromProperties(config);
  } catch (Exception e) {
    throw new DeployerRuntimeException("Exception reading configs from file " + args.getDbMergeConfigFile(), e);
  }
  DbPlatform dialect = DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType"));
  this.generateDiffs(dialect, dbNameLocationPairs, args.getOutputDir());
}

相关文章