Java 类org.apache.commons.configuration2.XMLConfiguration 实例源码

项目:beadledom    文件:XmlConfigurationSource.java   
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;
}
项目:oscm    文件:SequentialHostBalancerTest.java   
@Test
public void testBalancerStorageSequentialSingle() throws Exception {

    SequentialHostBalancer balancer = new SequentialHostBalancer();

    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@balancer]","elm1");

    balancer.setConfiguration(xmlConfiguration);

    VMwareDatacenterInventory inventory = new VMwareDatacenterInventory();

    VMwareHost elm = inventory.addHostSystem((VMwareDatacenterInventoryTest
            .createHostSystemProperties("elm1", "128", "1")));
    elm.setEnabled(true);

    balancer.setInventory(inventory);

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm1", elm.getName());

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm1", elm.getName());
}
项目:sponge    文件:DefaultConfigurationManager.java   
protected Pair<XMLConfiguration, URL> createXmlConfiguration(String fileName) {
    List<Lookup> lookups = Arrays.asList(new SystemPropertiesLookup(), new HomeLookup(), new ConfigLookup());

    Parameters params = new Parameters();
    FallbackBasePathLocationStrategy locationStrategy =
            new FallbackBasePathLocationStrategy(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, home);
    FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
            .configure(params.xml().setDefaultLookups(lookups).setLocationStrategy(locationStrategy).setFileName(fileName)
                    .setSchemaValidation(true).setEntityResolver(new ResourceSchemaResolver()));

    try {
        XMLConfiguration xmlConfiguration = builder.getConfiguration();

        return new ImmutablePair<>(xmlConfiguration, locationStrategy.getLocatedUrl());
    } catch (ConfigurationException e) {
        throw new ConfigException(e);
    }
}
项目:sponge    文件:DefaultConfigurationManager.java   
protected CommonsConfiguration createRootConfig() {
    MergeCombiner combiner = new MergeCombiner();
    combiner.addListNode(PluginManagerConstants.CFG_PLUGIN);

    CombinedConfiguration cc = new CombinedConfiguration(combiner);

    // Try to add explicit configuration
    if (configurationFilename != null) {
        logger.info("Loading configuration file {}...", configurationFilename);
        Pair<XMLConfiguration, URL> configurationPair = createXmlConfiguration(configurationFilename);

        cc.addConfiguration(configurationPair.getLeft());
        configurationFileUrl = configurationPair.getRight();
    }

    // Add default configuration
    cc.addConfiguration(createXmlConfiguration(ConfigurationConstants.DEFAULT_CONFIG).getLeft());

    // if (configurationFilename != null && logger.isDebugEnabled()) {
    // logger.debug("Initial XML configuration:\n{}", Utils.dumpConfiguration(cc));
    // }

    return new CommonsConfiguration(cc);
}
项目:PEF    文件:LiveCapture.java   
private static FramePseudonymizer initMetalPseudonymizerWith(final XMLConfiguration config) throws InvalidKeyException, ClassNotFoundException {
    Processor processor = new Processor();

    List<HierarchicalConfiguration<ImmutableNode>> fields = config.configurationsAt("fields.field");

    for (HierarchicalConfiguration field : fields) {
        List<HierarchicalConfiguration> parameters = field.childConfigurationsAt("algorithm.params");
        List<AlgorithmParameter> parameterList = new ArrayList<>();
        for (HierarchicalConfiguration parameter : parameters) {
            parameterList.add(new AlgorithmParameter(parameter.getString("name"), parameter.getString("value"), Class.forName(parameter.getString("type"))));
        }
        // Add the transformers
        processor.addTransformer(Constraints.CONSTRAINT_MAP.get(field.getString("constraint")), field.getString("name"),
                getParseValueTransformer(ParseValueTransformerFactory.TransformerId.valueOf(field.getString("algorithm.name")), parameterList));
        logger.info("Packets containing " + field.getString("name") +  " will be pseudonymized based on this constraint: " + field.getString("constraint")
                + ", with this algorithm "+ field.getString("algorithm.name") );
    }
    // TODO PEF-43:  Move and change functionality.
    if (config.getBoolean("checksum_reset")) {
        processor.addTransformer(Constraints.IPV4_UDP_DNS, "udpchecksum",new IPv4UDPChecksumCalculator())
                .addTransformer(Constraints.IPV6_UDP_DNS, "udpchecksum", new IPv6UDPChecksumCalculator())
                .addTransformer(Constraints.IPV4_UDP_DNS, "headerchecksum", new IPv4ChecksumCalculator())
                .addTransformer(Constraints.ICMP_DNS, "icmpchecksum", new IPv6UDPChecksumCalculator());
    }
    return new FramePseudonymizer(processor);
}
项目:MockTCPServer    文件:ConfigurationSettings.java   
private FileBasedConfigurationBuilder<XMLConfiguration> getConfigurationBuilder() {
    if (this.configurationBuilder == null) {
        final Parameters params = new Parameters();
        this.configurationBuilder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class)
                .configure(params.xml()
                        .setURL(this.getFileName())
                        .setValidating(false));
        this.configurationBuilder.setAutoSave(true);

        // If the file has not yet been written to the disk, as this is the first execution or the file has been deleted (deletion is a legitimate way to "reset to factory settings"), write it now.
        if (this.isConfigurationInitialisationEnabled() && !this.getDefaultFile().exists()) {
            // Reinitialise in order to pick up the newly created file.
            this.propertiesFile = null;
            this.save();
            this.configurationBuilder = null;
            this.getConfigurationBuilder();
        }
    }

    return this.configurationBuilder;
}
项目:oscm    文件:EquipartitionHostBalancerTest.java   
@Test
public void testBalancer_wrongConfig() throws Exception {
    // wrong configuration values should simply be ignored
    EquipartitionHostBalancer balancer = new EquipartitionHostBalancer();
    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@hosts]", "host1,host2,host3,host4,host5");
    xmlConfiguration.addProperty("[@memoryWeight]", "wrong");
    xmlConfiguration.addProperty("[@cpuWeight]", "wrong");
    xmlConfiguration.addProperty("[@vmWeight]", "");
    balancer.setConfiguration(xmlConfiguration);
}
项目:oscm    文件:EquipartitionHostBalancerTest.java   
private EquipartitionHostBalancer getBalancer(double memWeight,
        double cpuWeight, double vmWeight) throws IOException, ConfigurationException {
    EquipartitionHostBalancer balancer = new EquipartitionHostBalancer();
    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@hosts]", "host1,host2,host3,host4,host5");
    xmlConfiguration.addProperty("[@memoryWeight]", memWeight);
    xmlConfiguration.addProperty("[@cpuWeight]", cpuWeight);
    xmlConfiguration.addProperty("[@vmWeight]", vmWeight);
    balancer.setConfiguration(xmlConfiguration);
    return balancer;
}
项目:oscm    文件:EquipartitionStorageBalancerTest.java   
private EquipartitionStorageBalancer getBalancer(String storages)
    throws ConfigurationException, IOException {
    EquipartitionStorageBalancer balancer = new EquipartitionStorageBalancer();
    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@storage]", storages);
    balancer.setConfiguration(xmlConfiguration);
    return balancer;
}
项目:oscm    文件:SequentialStorageBalancerTest.java   
@Test
public void testSingle() throws Exception {

    SequentialStorageBalancer balancer = new SequentialStorageBalancer();

    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@storage]", "elm1");
    balancer.setConfiguration(xmlConfiguration);

    VMwareDatacenterInventory inventory = new VMwareDatacenterInventory();

    VMwareStorage elm = inventory.addStorage("host",
            VMwareDatacenterInventoryTest.createDataStoreProperties("elm1",
                    "100", "100"));
    elm.setEnabled(true);
    elm.setLimit(VMwareValue.parse("90%"));

    balancer.setInventory(inventory);

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm1", elm.getName());

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm1", elm.getName());
}
项目:PEF    文件:LiveCapture.java   
private static void testPseudonymizationSettings(final XMLConfiguration config) throws ConfigurationException, IllegalArgumentException, ClassNotFoundException {
    List<HierarchicalConfiguration<ImmutableNode>> fields = config.configurationsAt("fields.field");
    for (HierarchicalConfiguration field : fields) {
        // Test the name of the field.
        final String constraint = field.getString("constraint");
        final String fieldName = field.getString("name");
        final String algorithmName = field.getString("algorithm.name");
        if ( (fieldName == null) || (constraint == null) || (algorithmName == null) )
            throw new NoSuchElementException("Name of the field, constraint and algoritm needs to be set for each field.");
        // Test the constraint.
        if (!Constraints.CONSTRAINT_MAP.containsKey(field.getString("constraint"))) {
            throw new ConfigurationException(field.getString("constraint") + "should be defined in constraints list (Constraints.java)");
        }
        // TODO PEF-78: Test if the fieldName matches with the context.
        // TODO PEF-79: No expression support.
        // Test if the algorithm is part of the configured algorithms.
        List<HierarchicalConfiguration> parameters = field.childConfigurationsAt("algorithm.params");
        List<AlgorithmParameter> parameterList = new ArrayList<>();

        //TODO PEF-81: Create here a specific parameter type.
        for (HierarchicalConfiguration parameter : parameters) {
            parameterList.add(new AlgorithmParameter(parameter.getString("name"), parameter.getString("value"), Class.forName(parameter.getString("type"))));
        }
        final StringBuilder buffer = new StringBuilder();
        if (!testParseValueTransformerConfiguration(TransformerId.valueOf(algorithmName), parameterList, buffer)) {
            throw new ConfigurationException("Error in configuration for algorithm "+ algorithmName + " " + buffer.toString());
        }
    }
}
项目:standalone-app    文件:Helios.java   
private static Configuration loadConfiguration() throws IOException, ConfigurationException {
    Configurations configurations = new Configurations();
    File file = Constants.SETTINGS_FILE_XML;
    if (!file.exists()) {
        XMLConfiguration tempConfiguration = new XMLConfiguration();
        new FileHandler(tempConfiguration).save(file);
    }
    FileBasedConfigurationBuilder<XMLConfiguration> builder = configurations.xmlBuilder(file);
    builder.setAutoSave(true);
    return builder.getConfiguration();
}
项目:standalone-app    文件:BaseTransformerController.java   
protected Configuration getConfiguration() {
    try {
        return ((XMLConfiguration) configuration).configurationAt(transformerType.getInternalName() + "." + internalName, true);
    } catch (RuntimeException ex) {
        configuration.setProperty(transformerType.getInternalName() + "." + internalName + ".configured", true);
        return getConfiguration();
    }
}
项目:hybris-maven-plugin    文件:ExtensionFactoryTest.java   
private Set<String> readExtensionNames(final File folder) throws Exception {
    try (final InputStream extensionsXML = getClass().getResourceAsStream("extensions.xml")) {
        new File(folder, "bin/platform").mkdirs();
        Files.copy(extensionsXML, new File(folder, "bin/platform/extensions.xml").toPath());
    }

    final File hybrisPlatformDirectory = new File(folder, "bin/platform");
    final File platformExtensionsFile = new File(hybrisPlatformDirectory, "extensions.xml");
    final FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(
            XMLConfiguration.class).configure(new Parameters().xml().setFile(platformExtensionsFile));
    final XMLConfiguration platformExtensionsConfiguration = builder.getConfiguration();
    final List<String> extensionNames = Lists
            .newArrayList(platformExtensionsConfiguration.getList(String.class, "extensions.extension[@name]"));
    return new HashSet<>(extensionNames);
}
项目:standalone-app    文件:Helios.java   
private static Configuration loadConfiguration() throws IOException, ConfigurationException {
    Configurations configurations = new Configurations();
    File file = Constants.SETTINGS_FILE_XML;
    if (!file.exists()) {
        XMLConfiguration tempConfiguration = new XMLConfiguration();
        new FileHandler(tempConfiguration).save(file);
    }
    FileBasedConfigurationBuilder<XMLConfiguration> builder = configurations.xmlBuilder(file);
    builder.setAutoSave(true);
    return builder.getConfiguration();
}
项目:standalone-app    文件:BaseTransformerController.java   
protected Configuration getConfiguration() {
    try {
        return ((XMLConfiguration) configuration).configurationAt(transformerType.getInternalName() + "." + internalName, true);
    } catch (RuntimeException ex) {
        configuration.setProperty(transformerType.getInternalName() + "." + internalName + ".configured", true);
        return getConfiguration();
    }
}
项目:oscm    文件:SequentialHostBalancerTest.java   
@Test
public void testBalancerStorageSequentialMultiple() throws Exception {

    SequentialHostBalancer balancer = new SequentialHostBalancer();

    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@hosts]", "elm3,elm2,elm1,elm4");
    balancer.setConfiguration(xmlConfiguration);

    VMwareDatacenterInventory inventory = new VMwareDatacenterInventory();

    VMwareHost elm = inventory.addHostSystem((VMwareDatacenterInventoryTest
            .createHostSystemProperties("elm1", "128", "1")));
    elm.setEnabled(true);

    elm = inventory.addHostSystem((VMwareDatacenterInventoryTest
            .createHostSystemProperties("elm2", "128", "1")));
    elm.setEnabled(true);

    elm = inventory.addHostSystem((VMwareDatacenterInventoryTest
            .createHostSystemProperties("elm3", "128", "1")));
    elm.setEnabled(false);

    elm = inventory.addHostSystem((VMwareDatacenterInventoryTest
            .createHostSystemProperties("elm4", "128", "1")));
    elm.setEnabled(true);

    balancer.setInventory(inventory);

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm2", elm.getName());

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm2", elm.getName());

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm2", elm.getName());
}
项目:oscm    文件:SequentialStorageBalancerTest.java   
@Test
public void testMultiple() throws Exception {

    SequentialStorageBalancer balancer = new SequentialStorageBalancer();

    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@storage]", "elm1,elm2,elm3,elm4");
    balancer.setConfiguration(xmlConfiguration);

    VMwareDatacenterInventory inventory = new VMwareDatacenterInventory();

    // elm1 does not provide enough resources with respect to configured
    // limit
    VMwareStorage elm = inventory.addStorage("host",
            VMwareDatacenterInventoryTest.createDataStoreProperties("elm1",
                    "100", "40"));
    elm.setEnabled(true);
    elm.setLimit(VMwareValue.parse("50%"));

    elm = inventory.addStorage("host", VMwareDatacenterInventoryTest
            .createDataStoreProperties("elm2", "100", "100"));
    elm.setEnabled(true);
    elm.setLimit(VMwareValue.parse("90%"));

    elm = inventory.addStorage("host", VMwareDatacenterInventoryTest
            .createDataStoreProperties("elm3", "100", "100"));
    elm.setEnabled(false);
    elm.setLimit(VMwareValue.parse("90%"));

    elm = inventory.addStorage("host", VMwareDatacenterInventoryTest
            .createDataStoreProperties("elm4", "100", "100"));
    elm.setEnabled(true);
    elm.setLimit(VMwareValue.parse("90%"));

    balancer.setInventory(inventory);

    // getting elm2 since elm1 is not applicable
    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm2", elm.getName());

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm2", elm.getName());

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm2", elm.getName());

}
项目:oscm    文件:SequentialStorageBalancerTest.java   
@Test
public void testMultipleReduce() throws Exception {

    SequentialStorageBalancer balancer = new SequentialStorageBalancer();

    String balancerConfig = "<host><balancer storage=\"elm1,elm2,elm3\" /></host>";
    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.addProperty("[@storage]", "elm1,elm2,elm3");
    balancer.setConfiguration(xmlConfiguration);

    VMwareDatacenterInventory inventory = new VMwareDatacenterInventory();

    VMwareStorage elm = inventory.addStorage("host",
            VMwareDatacenterInventoryTest.createDataStoreProperties("elm1",
                    "100", "100"));
    elm.setEnabled(true);
    elm.setLimit(VMwareValue.parse("90%"));

    elm = inventory.addStorage("host", VMwareDatacenterInventoryTest
            .createDataStoreProperties("elm2", "100", "100"));
    elm.setEnabled(true);
    elm.setLimit(VMwareValue.parse("90%"));

    balancer.setInventory(inventory);

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm1", elm.getName());

    // Now shorten list, so "elm2" is not longer next element
    inventory = new VMwareDatacenterInventory();

    elm = inventory.addStorage("host", VMwareDatacenterInventoryTest
            .createDataStoreProperties("elm3", "100", "100"));
    elm.setEnabled(true);
    elm.setLimit(VMwareValue.parse("90%"));
    balancer.setInventory(inventory);

    elm = balancer.next(properties);
    assertNotNull(elm);
    assertEquals("elm3", elm.getName());
}
项目:commons-configuration2-jackson    文件:BuiltInXmlConfigurationTests.java   
@Override
protected XMLConfiguration create(final Map<String, Object> properties) throws ConfigurationException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.initFileLocator(FileLocatorUtils.fileLocator().create());
    return configuration;
}