当前位置: 首页>>代码示例>>Java>>正文


Java HierarchicalConfiguration类代码示例

本文整理汇总了Java中org.apache.commons.configuration2.HierarchicalConfiguration的典型用法代码示例。如果您正苦于以下问题:Java HierarchicalConfiguration类的具体用法?Java HierarchicalConfiguration怎么用?Java HierarchicalConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HierarchicalConfiguration类属于org.apache.commons.configuration2包,在下文中一共展示了HierarchicalConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initMetalPseudonymizerWith

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
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);
}
 
开发者ID:NCSC-NL,项目名称:PEF,代码行数:27,代码来源:LiveCapture.java

示例2: ProjectConfig

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
protected ProjectConfig(HierarchicalConfiguration<ImmutableNode> config, @Nullable String metaborgVersion,
        @Nullable Collection<IExportConfig> sources, @Nullable Collection<LanguageIdentifier> compileDeps,
        @Nullable Collection<LanguageIdentifier> sourceDeps, @Nullable Collection<LanguageIdentifier> javaDeps) {
    this(config);

    if(metaborgVersion != null) {
        config.setProperty(PROP_METABORG_VERSION, metaborgVersion);
    }
    if(sources != null) {
        config.setProperty(PROP_SOURCES, sources);
    }
    if(compileDeps != null) {
        config.setProperty(PROP_COMPILE_DEPENDENCIES, compileDeps);
    }
    if(sourceDeps != null) {
        config.setProperty(PROP_SOURCE_DEPENDENCIES, sourceDeps);
    }
    if(javaDeps != null) {
        config.setProperty(PROP_JAVA_DEPENDENCIES, javaDeps);
    }
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:22,代码来源:ProjectConfig.java

示例3: getFromConfigFile

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
/**
 * Gets the configuration from the given file.
 *
 * @param configFile
 *            The configuration file with the configuration.
 * @return The configuration, or <code>null</code> when no configuration could be retrieved.
 */
public ConfigRequest<TConfig> getFromConfigFile(FileObject configFile, FileObject rootFolder) {
    final HierarchicalConfiguration<ImmutableNode> configuration;
    try {
        configuration = readConfig(configFile, rootFolder);
    } catch(ConfigurationException | IOException e) {
        // @formatter:off
        final IMessage message = MessageBuilder
            .create()
            .withSource(configFile)
            .withMessage("Unable to read configuration from " + configFile)
            .withException(e)
            .build();
        // @formatter:on
        return new ConfigRequest<>(message);
    }
    
    if(configuration != null) {
        return toConfig(configuration, configFile);
    } else {
        return new ConfigRequest<>();
    }
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:30,代码来源:AConfigService.java

示例4: LanguageSpecConfig

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
protected LanguageSpecConfig(HierarchicalConfiguration<ImmutableNode> config, ProjectConfig projectConfig,
    @Nullable LanguageIdentifier id, @Nullable String name, @Nullable Boolean sdfEnabled,
    @Nullable Sdf2tableVersion sdf2tableVersion, @Nullable Boolean dataDependent, @Nullable String parseTable,
    @Nullable String completionsParseTable, @Nullable JSGLRVersion jsglrVersion,
    @Nullable Collection<LanguageContributionIdentifier> langContribs,
    @Nullable Collection<IGenerateConfig> generates, @Nullable Collection<IExportConfig> exports,
    @Nullable Collection<String> pardonedLanguages, @Nullable Boolean useBuildSystemSpec) {
    super(config, projectConfig, id, name, sdfEnabled, parseTable, completionsParseTable, sdf2tableVersion,
        dataDependent, jsglrVersion, langContribs, generates, exports);

    if(pardonedLanguages != null) {
        config.setProperty(PROP_PARDONED_LANGUAGES, pardonedLanguages);
    }
    if(useBuildSystemSpec != null) {
        config.setProperty(PROP_USE_BUILD_SYSTEM_SPEC, useBuildSystemSpec);
    }
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:18,代码来源:LanguageSpecConfig.java

示例5: parseBalancer

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <E extends VMwareBalancer<?>> E parseBalancer(
        HierarchicalConfiguration parent, Class<E> targetClass,
        Class<? extends E> defaultBalancer,
        VMwareDatacenterInventory inventory) throws Exception {

    String balancerClass = parent.getString("balancer[@class]");
    Class<?> loadedClass = null;
    if (balancerClass != null) {
        loadedClass = this.getClass().getClassLoader()
                .loadClass(balancerClass);
        if (!targetClass.isAssignableFrom(loadedClass)) {
            loadedClass = null;
            logger.warn("The configured balancer '" + balancerClass
                    + "' is not of type " + targetClass.getSimpleName());
        }
    }
    if (loadedClass == null) {
        balancerClass = defaultBalancer.getName();
        parent.addProperty("balancer[@class]", balancerClass);
        loadedClass = defaultBalancer;
    }
    HierarchicalConfiguration balancerConfig = parent
            .configurationAt(ELEMENT_BALANCER);
    E balancer = (E) loadedClass.newInstance();
    balancer.setConfiguration(balancerConfig);
    balancer.setInventory(inventory);
    return balancer;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:LoadBalancerConfiguration.java

示例6: setConfiguration

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@Override
public void setConfiguration(HierarchicalConfiguration config) {
    if (config != null) {
        String storages = config.getString("[@storage]");
        if (storages == null || storages.trim().length() == 0) {
            throw new IllegalArgumentException(
                    "No storage reference defined for balancer");
        }
        String[] elms = storages.split(",");
        for (String x : elms) {
            datastoreNames.add(x.toString().trim());
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:StorageBalancer.java

示例7: setConfiguration

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@Override
public void setConfiguration(HierarchicalConfiguration xmlConfig) {
    if (xmlConfig != null) {
        String hosts = xmlConfig.getString("[@hosts]");
        if (hosts != null) {
            String[] elms = hosts.split(",");
            for (String x : elms) {
                hostNames.add(x.toString().trim());
            }
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:HostBalancer.java

示例8: testBalancer_noHostsObject

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@Test
public void testBalancer_noHostsObject() throws Exception {
    // no host elements should not create an exception
    HierarchicalConfiguration configuration = Mockito
            .mock(HierarchicalConfiguration.class);
    // the mock shall not return a list on getList call
    Mockito.when(configuration.getList(Matchers.anyString())).thenReturn(
            null);
    new EquipartitionHostBalancer().setConfiguration(configuration);
    // no exception must occur
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:EquipartitionHostBalancerTest.java

示例9: testBalancer_noStorageObject

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testBalancer_noStorageObject() throws Exception {
    // no storage elements should create an exception
    HierarchicalConfiguration configuration = Mockito
            .mock(HierarchicalConfiguration.class);
    // the mock shall not return a list on getList call
    Mockito.when(configuration.getList(Matchers.anyString())).thenReturn(
            null);
    new EquipartitionStorageBalancer().setConfiguration(configuration);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:EquipartitionStorageBalancerTest.java

示例10: createConfigurations

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
protected CommonsConfiguration[] createConfigurations(List<HierarchicalConfiguration<ImmutableNode>> subs) {
    CommonsConfiguration[] result = new CommonsConfiguration[subs.size()];

    for (int i = 0; i < result.length; i++) {
        result[i] = new CommonsConfiguration((BaseHierarchicalConfiguration) subs.get(i));
    }

    return result;
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:10,代码来源:CommonsConfiguration.java

示例11: testPseudonymizationSettings

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
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());
        }
    }
}
 
开发者ID:NCSC-NL,项目名称:PEF,代码行数:30,代码来源:LiveCapture.java

示例12: JacksonConfiguration

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
/**
 * Initializes a new instance of the {@link JacksonConfiguration} class.
 *
 * @param factory The Jackson factory to use.
 * @param config  The configuration whose nodes to copy into this configuration.
 */
protected JacksonConfiguration(final JsonFactory factory, final HierarchicalConfiguration<ImmutableNode> config) {
    super(config);

    Preconditions.checkNotNull(factory);

    this.module = new SimpleModule();
    this.mapper = new ObjectMapper(factory);
    this.mapper.registerModule(this.module);
}
 
开发者ID:Virtlink,项目名称:commons-configuration2-jackson,代码行数:16,代码来源:JacksonConfiguration.java

示例13: readConfiguration

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@Test
public void readConfiguration() throws IOException, ConfigurationException {
    // Arrange
    final T sut = create();
    final String input = getExampleConfiguration();

    // Act
    final StringReader reader = new StringReader(input);
    sut.read(reader);

    final HierarchicalConfiguration<ImmutableNode> objs = sut.configurationAt("listOfObjs(0)", true);

    // Assert
    assertThat(sut.getString("name"), is("testName"));
    assertThat(sut.getString("obj.name"), is("test"));
    assertThat(sut.getInt("obj.value"), is(1));
    assertThat(sut.getString("listOfObjs(0).name"), is("testname"));
    assertThat(sut.getInt("listOfObjs(0).value"), is(4));
    assertThat(sut.getString("listOfObjs(1).name"), is("other"));
    assertThat(sut.getInt("listOfObjs(1).value"), is(20));
    assertThat(sut.getStringArray("listOfObjs.name"), is(new String[]{"testname", "other"}));
    assertThat(sut.getProperty("nullValue"), is(nullValue()));
    assertThat(sut.getProperty("emptyList"), is(nullValue()));
    assertThat(sut.getString("listOfComplexObjs(0).someObj.name"), is("a name"));
    assertThat(sut.getInt("listOfComplexObjs(0).someObj.value"), is(20));
    assertThat(sut.getString("listOfComplexObjs(1).someObj.name"), is("another name"));
    assertThat(sut.getInt("listOfComplexObjs(1).someObj.value"), is(40));
}
 
开发者ID:Virtlink,项目名称:commons-configuration2-jackson,代码行数:29,代码来源:ConfigurationTests.java

示例14: toConfig

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@Override protected ConfigRequest<ISpoofaxLanguageSpecConfig>
    toConfig(HierarchicalConfiguration<ImmutableNode> config, FileObject configFile) {
    final SpoofaxProjectConfig projectConfig = new SpoofaxProjectConfig(config);
    final SpoofaxLanguageSpecConfig languageSpecConfig = new SpoofaxLanguageSpecConfig(config, projectConfig);
    final MessageBuilder mb = MessageBuilder.create().asError().asInternal().withSource(configFile);
    final Collection<IMessage> messages = languageSpecConfig.validate(mb);
    return new ConfigRequest<ISpoofaxLanguageSpecConfig>(languageSpecConfig, messages);
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:9,代码来源:SpoofaxLanguageSpecConfigService.java

示例15: fromConfig

import org.apache.commons.configuration2.HierarchicalConfiguration; //导入依赖的package包/类
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ISpoofaxLanguageSpecConfig config) {
    if(!(config instanceof IConfig)) {
        configBuilder.reset();
        configBuilder.copyFrom(config);
        config = configBuilder.build(null);
    }
    return ((IConfig) config).getConfig();
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:9,代码来源:SpoofaxLanguageSpecConfigService.java


注:本文中的org.apache.commons.configuration2.HierarchicalConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。