Java 类org.apache.commons.configuration.ConfigurationRuntimeException 实例源码

项目:JCLAL    文件:kFoldCrossValidation.java   
/**
 * @param configuration
 *            The configuration of K-Fold cross validation. The XML labels
 *            supported are:
 *
 *            <ul>
 *            <li><b>stratify= boolean</b></li>
 *            <li><b>num-folds= int</b></li>
 *            </ul>
 */
@Override
public void configure(Configuration configuration) {
    super.configure(configuration);

    // Set stratify (default false)
    boolean stratifyValue = configuration.getBoolean("stratify", stratify);
    setStratify(stratifyValue);

    // num folds
    int numFols = configuration.getInt("num-folds", numFolds);
    if (numFols < 1) {
        throw new ConfigurationRuntimeException("\n<num-folds>" + numFols + "</num-folds>. " + "num-folds > 0");
    }
    setNumFolds(numFols);
}
项目:JCLAL    文件:HoldOut.java   
/**
 * @param configuration
 *            The configuration of Hold Out.
 *
 *            The XML labels supported are:
 *
 *            <ul>
 *            <li><b>percentage-split= double</b></li>
 *            </ul>
 */
@Override
public void configure(Configuration configuration) {

    super.configure(configuration);

    // the percent of instances used to train
    double percentTrain = configuration.getDouble("percentage-split", percentageToSplit);

    String perc = "\n<percentage-split>" + percentTrain + "</percentage-split>";

    if (percentTrain <= 0) {
        throw new ConfigurationRuntimeException(perc + ". percentage-split > 0");
    }
    if (percentTrain >= 100) {
        throw new ConfigurationRuntimeException(perc + ". percentage-split < 100");
    }

    setPercentageToSplit(percentTrain);
}
项目:metron    文件:ConfigurationManager.java   
/**
 * Common method to load content of all configuration resources defined in
 * 'config-definition.xml'.
 * 
 * @param configDefFilePath
 *          the config def file path
 * @return Configuration
 */
public static Configuration getConfiguration(String configDefFilePath) {
  if (configurationsCache.containsKey(configDefFilePath)) {
    return configurationsCache.get(configDefFilePath);
  }
  CombinedConfiguration configuration = null;
  synchronized (configurationsCache) {
    if (configurationsCache.containsKey(configDefFilePath)) {
      return configurationsCache.get(configDefFilePath);
    }
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    String filePath = getConfigDefFilePath(configDefFilePath);
    LOGGER.info("loading from 'configDefFilePath' : {}", filePath);
    builder.setFile(new File(filePath));
    try {
      configuration = builder.getConfiguration(true);
      configurationsCache.put(filePath, configuration);
    } catch (ConfigurationException|ConfigurationRuntimeException e) {
      LOGGER.info("Exception in loading property files.", e);
    }
  }
  return configuration;
}
项目:configurations-yaml    文件:ConfigurationAssert.java   
/**
 * Helper method for converting a file to a URL.
 *
 * @param file the file
 * @return the corresponding URL
 * @throws ConfigurationRuntimeException if the URL cannot be constructed
 */
private static URL urlFromFile(File file)
{
    try
    {
        return file.toURI().toURL();
    }
    catch (MalformedURLException mex)
    {
        throw new ConfigurationRuntimeException(mex);
    }
}
项目:JCLAL    文件:AbstractSampling.java   
/**
 * @param configuration
 *            The configuration object for Abstract sampling.
 *            <p>
 *            <b>percentage-to-select= double</b>
 *            </p>
 */
@Override
public void configure(Configuration configuration) {

    double percentageInstancesToLabelledTemp = configuration.getDouble("percentage-to-select", 10);
    String perc = "\n<percentage-to-select>" + percentageInstancesToLabelledTemp + "</percentage-to-select>";
    if (percentageInstancesToLabelledTemp <= 0) {
        throw new ConfigurationRuntimeException(perc + ". percentage-to-select > 0");
    }
    if (percentageInstancesToLabelledTemp > 100) {
        throw new ConfigurationRuntimeException(perc + ". percentage-to-select <= 100");
    }
    setPercentageInstancesToLabelled(percentageInstancesToLabelledTemp);

}
项目:JCLAL    文件:AbstractBatchMode.java   
/**
 *
 * @param configuration
 *            The configuration of Abstract Batch Mode.
 *
 *            The XML labels supported are:
 *            <ul>
 *            <li>batch-size= int</li>
 *            </ul>
 */
@Override
public void configure(Configuration configuration) {

    // Set batchSize
    int batchT = configuration.getInt("batch-size", batchSize);
    if (batchT <= 0) {
        throw new ConfigurationRuntimeException(
                "\nIllegal batch size: <batch-size>" + batchT + "</batch-size>" + ". Batch size > 0");
    }
    setBatchSize(batchT);
}
项目:incubator-rya    文件:RyaSailFactory.java   
/**
 * Create a {@link MongoClient} that is connected to the configured database.
 *
 * @param mongoConf - Configures what will be connected to. (not null)
 * @throws ConfigurationRuntimeException An invalid port was provided by {@code mongoConf}.
 * @throws MongoException Couldn't connect to the MongoDB database.
 */
private static MongoClient createMongoClient(final MongoDBRdfConfiguration mongoConf) throws ConfigurationRuntimeException, MongoException {
    requireNonNull(mongoConf);
    requireNonNull(mongoConf.getMongoHostname());
    requireNonNull(mongoConf.getMongoPort());
    requireNonNull(mongoConf.getMongoDBName());

    // Connect to a running MongoDB server.
    final int port;
    try {
        port = Integer.parseInt( mongoConf.getMongoPort() );
    } catch(final NumberFormatException e) {
        throw new ConfigurationRuntimeException("Port '" + mongoConf.getMongoPort() + "' must be an integer.");
    }

    final ServerAddress server = new ServerAddress(mongoConf.getMongoHostname(), port);

    // Connect to a specific MongoDB Database if that information is provided.
    final String username = mongoConf.getMongoUser();
    final String database = mongoConf.getMongoDBName();
    final String password = mongoConf.getMongoPassword();
    if(username != null && password != null) {
        final MongoCredential cred = MongoCredential.createCredential(username, database, password.toCharArray());
        return new MongoClient(server, Arrays.asList(cred));
    } else {
        return new MongoClient(server);
    }
}
项目:incubator-rya    文件:GeoRyaSailFactory.java   
/**
 * Create a {@link MongoClient} that is connected to the configured database.
 *
 * @param mongoConf - Configures what will be connected to. (not null)
 * @throws ConfigurationRuntimeException An invalid port was provided by {@code mongoConf}.
 * @throws MongoException Couldn't connect to the MongoDB database.
 */
private static MongoClient createMongoClient(final MongoDBRdfConfiguration mongoConf) throws ConfigurationRuntimeException, MongoException {
    requireNonNull(mongoConf);
    requireNonNull(mongoConf.getMongoHostname());
    requireNonNull(mongoConf.getMongoPort());
    requireNonNull(mongoConf.getMongoDBName());

    // Connect to a running MongoDB server.
    final int port;
    try {
        port = Integer.parseInt( mongoConf.getMongoPort() );
    } catch(final NumberFormatException e) {
        throw new ConfigurationRuntimeException("Port '" + mongoConf.getMongoPort() + "' must be an integer.");
    }

    final ServerAddress server = new ServerAddress(mongoConf.getMongoHostname(), port);

    // Connect to a specific MongoDB Database if that information is provided.
    final String username = mongoConf.getMongoUser();
    final String database = mongoConf.getMongoDBName();
    final String password = mongoConf.getMongoPassword();
    if(username != null && password != null) {
        final MongoCredential cred = MongoCredential.createCredential(username, database, password.toCharArray());
        return new MongoClient(server, Arrays.asList(cred));
    } else {
        return new MongoClient(server);
    }
}
项目:pinot    文件:QuotaConfigTest.java   
@Test(expectedExceptions = ConfigurationRuntimeException.class)
public void testBadConfig()
    throws IOException {
  String quotaConfigStr = "{\"storage\":\"-1M\"}";
  QuotaConfig quotaConfig = new ObjectMapper().readValue(quotaConfigStr, QuotaConfig.class);
  quotaConfig.validate();
}
项目:JCLAL    文件:RealScenario.java   
@Override
protected void setDataConfiguration(Configuration configuration) {
    // Set multiLabel flag
    boolean multi = configuration.getBoolean("multi-label", false);
    setMultiLabel(multi);

    // Set multiInstance flag
    boolean multiInstance = configuration.getBoolean("multi-instance", false);
    setMultiInstance(multiInstance);

    // Set the xml file, it is used in the case of a multi-label
    // dataset
    String xml = configuration.getString("file-xml", "");
    setXmlPath(xml);

    // the multi-label elements are verified
    if (multi && xml.isEmpty()) {
        throw new ConfigurationRuntimeException("\nThe multi-label flag is " + "enabled and the xml path is empty. "
                + "<multi-label>true</multi-label>" + " <file-xml></file-xml>");
    }

    // Set file labeled
    String fileLabeled = configuration.getString("file-labeled", "");
    setFileLabeledDataset(fileLabeled);

    // Set file unlabeled
    String fileUnlabeled = configuration.getString("file-unlabeled", "");
    setFileUnlabeledDataset(fileUnlabeled);

    if (fileLabeled.isEmpty() || fileUnlabeled.isEmpty()) {
        throw new ConfigurationRuntimeException("\n <file-labeled> and <file-unlabeled> tags must be defined.");
    }

    // Set file test
    String fileTest = configuration.getString("file-test", "");

    if (fileTest.isEmpty()) {
        /*
         * Logger.getLogger(RealScenario.class.getName()).log(Level.INFO,
         * "The param <file-test> is empty, the active learning algorithm require this property "
         * +
         * "for evaluating the constructed model, but in real scenario is not really necessary. In this case, "
         * + "we assign the <file-unlabeled> as <file-test>.");
         */
        fileTest = fileUnlabeled;
    }

    setFileTestDataset(fileTest);

    // Set class attribute
    int classAttributeT = configuration.getInt("class-attribute", -1);

    setClassAttribute(classAttributeT);
}
项目:spring-open    文件:SdnIp.java   
@Override
public void init(FloodlightModuleContext context)
        throws FloodlightModuleException {

    bgpRoutes = new ConcurrentInvertedRadixTree<>(
            new DefaultByteArrayNodeFactory());
    interfaceRoutes = new ConcurrentInvertedRadixTree<>(
            new DefaultByteArrayNodeFactory());
    externalNetworkSwitchPorts = new HashSet<SwitchPort>();

    ribUpdates = new LinkedBlockingQueue<>();

    // Register REST handler.
    restApi = context.getServiceImpl(IRestApiService.class);
    proxyArp = context.getServiceImpl(IProxyArpService.class);

    controllerRegistryService = context
            .getServiceImpl(IControllerRegistryService.class);
    pathRuntime = context.getServiceImpl(IPathCalcRuntimeService.class);
    linkDiscoveryService = context.getServiceImpl(ILinkDiscoveryService.class);

    intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(
            controllerRegistryService);

    // TODO: initialize intentService

    pushedRouteIntents = new ConcurrentHashMap<>();

    prefixesWaitingOnArp = Multimaps.synchronizedSetMultimap(
            HashMultimap.<InetAddress, RibUpdate>create());

    //flowCache = new FlowCache(floodlightProvider);

    bgpUpdatesExecutor = Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setNameFormat("bgp-updates-%d").build());

    // Read in config values
    bgpdRestIp = context.getConfigParams(this).get("BgpdRestIp");
    if (bgpdRestIp == null) {
        log.error("BgpdRestIp property not found in config file");
        throw new ConfigurationRuntimeException(
                "BgpdRestIp property not found in config file");
    } else {
        log.info("BgpdRestIp set to {}", bgpdRestIp);
    }

    routerId = context.getConfigParams(this).get("RouterId");
    if (routerId == null) {
        log.error("RouterId property not found in config file");
        throw new ConfigurationRuntimeException(
                "RouterId property not found in config file");
    } else {
        log.info("RouterId set to {}", routerId);
    }

    String configFilenameParameter = context.getConfigParams(this).get("configfile");
    if (configFilenameParameter != null) {
        currentConfigFilename = configFilenameParameter;
    }
    log.debug("Config file set to {}", currentConfigFilename);

    readConfiguration(currentConfigFilename);
}
项目:pinot    文件:QuotaConfig.java   
public void validate() {
  if (_storage != null && DataSize.toBytes(_storage) < 0) {
    LOGGER.error("Failed to convert storage quota config: {} to bytes", _storage);
    throw new ConfigurationRuntimeException("Failed to convert storage quota config: " + _storage + " to bytes");
  }
}
项目:JCLAL    文件:MultiLabel3DimensionalQueryStrategy.java   
/**
 *
 * @param configuration
 *            The configuration object for
 *            MultiLabel3DimensionalQueryStrategy
 *
 *            The XML labels supported are:
 *            <ul>
 *            <li>evidence-dimension: The possible values are [C, S]</li>
 *            <li>class-dimension: The possible values are [M, A, R]</li>
 *            <li>weight-dimension: The possible values are [N, M]</li>
 *            </ul>
 */
@Override
public void configure(Configuration configuration) {

    super.configure(configuration);

    evidenceDimension = configuration.getString("evidence-dimension", "C").toCharArray()[0];
    classDimension = configuration.getString("class-dimension", "M").toCharArray()[0];
    weightDimension = configuration.getString("weight-dimension", "N").toCharArray()[0];

    switch (evidenceDimension) {

    case 'C':

        setMaximal(false);

        break;

    case 'S':

        setMaximal(true);

        break;

    default:
        throw new ConfigurationRuntimeException("For the evidence dimension the options are C and S");
    }

    switch (classDimension) {

    case 'M':

        break;

    case 'A':

        break;

    case 'R':

        break;

    default:
        throw new ConfigurationRuntimeException("For the class dimension the options are M, A and R");
    }

    switch (weightDimension) {

    case 'N':

        break;

    case 'W':

        break;

    default:
        throw new ConfigurationRuntimeException("For the weight dimension the options are N and W");
    }

}
项目:JCLAL    文件:SenderEmail.java   
/**
 * @param configuration
 *            The configuration of SenderEmail.
 *
 *            The XML labels supported are:
 *            <ul>
 *            <li>smtp-host= ip</li>
 *            <li>smtp-port= int</li>
 *            <li>to= email</li>
 *            <li>from= email</li>
 *            <li>attach-report-file=boolean</li>
 *            <li>user=String</li>
 *            <li>pass=String</li>
 *            </ul>
 */
@Override
public void configure(Configuration configuration) {

    String hostT = configuration.getString("smtp-host", "");
    if (hostT.isEmpty()) {
        throw new ConfigurationRuntimeException("\nThe tag <smtp-host></smtp-host> is empty.");
    }

    setHost(hostT);

    int portT = configuration.getInt("smtp-port", 21);

    setPort(portT);

    String fromT = configuration.getString("from", "");

    if (fromT.isEmpty()) {
        throw new ConfigurationRuntimeException("\nThe tag <from></from> is empty. ");
    }

    setFrom(fromT);

    // Number of defined recipients
    int numberRecipients = configuration.getList("to").size();

    if (numberRecipients == 0) {
        throw new ConfigurationRuntimeException("\nAt least one <to></to> tag must be defined. ");
    }

    // For each recipients in list
    for (int i = 0; i < numberRecipients; i++) {

        String header = "to(" + i + ")";

        // recipient
        String recipientName = configuration.getString(header, "");

        // Add this recipient
        toRecipients.append(recipientName).append(";");
    }

    toRecipients.deleteCharAt(toRecipients.length() - 1);

    boolean attach = configuration.getBoolean("attach-report-file", false);

    setAttachReporFile(attach);

    String userT = configuration.getString("user", "");

    if (userT.isEmpty()) {
        throw new ConfigurationRuntimeException("\nThe tag <user></user> is empty. ");
    }

    setUser(userT);

    String passT = configuration.getString("pass", "");

    if (passT.isEmpty()) {
        throw new ConfigurationRuntimeException("\nThe tag <pass></pass> is empty. ");
    }

    setPass(passT);
}