Example usage for org.apache.commons.configuration HierarchicalConfiguration getInt

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getInt

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration getInt.

Prototype

public int getInt(String key) 

Source Link

Usage

From source file:com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java

private static SolutionAcceptor getAcceptor(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp,
        Set<PrioritizedVRAListener> algorithmListeners, TypedMap typedMap, int solutionMemory) {
    String acceptorName = strategyConfig.getString("acceptor[@name]");
    if (acceptorName == null)
        throw new IllegalStateException("no solution acceptor is defined");
    String acceptorId = strategyConfig.getString("acceptor[@id]");
    if (acceptorId == null)
        acceptorId = "noId";
    AcceptorKey acceptorKey = new AcceptorKey(makeKey(acceptorName, acceptorId));
    SolutionAcceptor definedAcceptor = typedMap.get(acceptorKey);
    if (definedAcceptor != null)
        return definedAcceptor;
    if (acceptorName.equals("acceptNewRemoveWorst")) {
        GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }//from w  ww.java 2s  .  co  m
    if (acceptorName.equals("acceptNewRemoveFirst")) {
        AcceptNewRemoveFirst acceptor = new AcceptNewRemoveFirst(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("greedyAcceptance")) {
        GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("schrimpfAcceptance")) {
        String nuWarmupIterations = strategyConfig.getString("acceptor.warmup");
        double alpha = strategyConfig.getDouble("acceptor.alpha");
        SchrimpfAcceptance schrimpf = new SchrimpfAcceptance(solutionMemory, alpha);
        if (nuWarmupIterations != null) {
            SchrimpfInitialThresholdGenerator iniThresholdGenerator = new SchrimpfInitialThresholdGenerator(
                    schrimpf, Integer.parseInt(nuWarmupIterations));
            algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, iniThresholdGenerator));
        } else {
            double threshold = strategyConfig.getDouble("acceptor.initialThreshold");
            schrimpf.setInitialThreshold(threshold);
        }
        algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
        typedMap.put(acceptorKey, schrimpf);
        return schrimpf;
    }
    if (acceptorName.equals("experimentalSchrimpfAcceptance")) {
        int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup");
        double alpha = strategyConfig.getDouble("acceptor.alpha");
        ExperimentalSchrimpfAcceptance schrimpf = new ExperimentalSchrimpfAcceptance(solutionMemory, alpha,
                iterOfSchrimpf);
        algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
        typedMap.put(acceptorKey, schrimpf);
        return schrimpf;
    } else {
        throw new IllegalStateException("solution acceptor " + acceptorName + " is not known");
    }
}

From source file:jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java

private static SolutionAcceptor getAcceptor(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp,
        Set<PrioritizedVRAListener> algorithmListeners, TypedMap typedMap, int solutionMemory) {
    String acceptorName = strategyConfig.getString("acceptor[@name]");
    if (acceptorName == null)
        throw new IllegalStateException("no solution acceptor is defined");
    String acceptorId = strategyConfig.getString("acceptor[@id]");
    if (acceptorId == null)
        acceptorId = "noId";
    AcceptorKey acceptorKey = new AcceptorKey(makeKey(acceptorName, acceptorId));
    SolutionAcceptor definedAcceptor = typedMap.get(acceptorKey);
    if (definedAcceptor != null)
        return definedAcceptor;
    if (acceptorName.equals("acceptNewRemoveWorst")) {
        GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }/*  w w w. j a va  2  s .  c  o m*/
    if (acceptorName.equals("acceptNewRemoveFirst")) {
        AcceptNewRemoveFirst acceptor = new AcceptNewRemoveFirst(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("greedyAcceptance")) {
        GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("greedyAcceptance_minVehFirst")) {
        GreedyAcceptance_minVehFirst acceptor = new GreedyAcceptance_minVehFirst(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("schrimpfAcceptance")) {
        String nuWarmupIterations = strategyConfig.getString("acceptor.warmup");
        double alpha = strategyConfig.getDouble("acceptor.alpha");
        SchrimpfAcceptance schrimpf = new SchrimpfAcceptance(solutionMemory, alpha);
        if (nuWarmupIterations != null) {
            SchrimpfInitialThresholdGenerator iniThresholdGenerator = new SchrimpfInitialThresholdGenerator(
                    schrimpf, Integer.parseInt(nuWarmupIterations));
            algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, iniThresholdGenerator));
        } else {
            double threshold = strategyConfig.getDouble("acceptor.initialThreshold");
            schrimpf.setInitialThreshold(threshold);
        }
        algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
        typedMap.put(acceptorKey, schrimpf);
        return schrimpf;
    }
    if (acceptorName.equals("experimentalSchrimpfAcceptance")) {
        int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup");
        double alpha = strategyConfig.getDouble("acceptor.alpha");
        ExperimentalSchrimpfAcceptance schrimpf = new ExperimentalSchrimpfAcceptance(solutionMemory, alpha,
                iterOfSchrimpf);
        algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
        typedMap.put(acceptorKey, schrimpf);
        return schrimpf;
    } else {
        throw new IllegalStateException("solution acceptor " + acceptorName + " is not known");
    }
}

From source file:net.fenyo.gnetwatch.GUI.GUI.java

/**
   * Parses a configuration file to create initial targets.
   * @param filename configuration file.
   * @return void./*from   w w w  .  j av  a2  s.  c om*/
   */
public void createFromXML(final String filename) {
    final GUI gui = this;

    asyncExec(new Runnable() {
        public void run() {
            synchronized (synchro) {
                final Session session = synchro.getSessionFactory().getCurrentSession();
                session.beginTransaction();

                try {
                    final XMLConfiguration initial = new XMLConfiguration(filename);
                    initial.setExpressionEngine(new XPathExpressionEngine());

                    // limitation de l'implmentation : on n'autorise que les parents de type groupe

                    for (final HierarchicalConfiguration subconf : (java.util.List<HierarchicalConfiguration>) initial
                            .configurationsAt("/objects/target")) {
                        if (subconf.getProperty("@targetType").equals("group")) {
                            final String name = subconf.getString("name");

                            final java.util.List<String> parents = (java.util.List<String>) subconf
                                    .getList("parent[@parentType='group']");
                            if (parents.size() == 0) {
                                final TargetGroup target_group = new TargetGroup(
                                        "added by initial configuration", name);
                                target_group.addTarget(gui, user_defined);
                            } else
                                for (final String parent : parents) {
                                    final TargetGroup foo = new TargetGroup("temporary", parent);
                                    final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
                                    if (target_parent == foo)
                                        log.error("Initial configuration: parent does not exist");
                                    else {
                                        final TargetGroup target_group = new TargetGroup(
                                                "added by initial configuration", name);
                                        target_group.addTarget(gui, target_parent);
                                    }
                                }
                        }

                        if (subconf.getProperty("@targetType").equals("ipv4")) {
                            final String address = subconf.getString("address");

                            java.util.List<String> parents = (java.util.List<String>) subconf
                                    .getList("parent[@parentType='group']");
                            if (parents.size() != 0)
                                for (final String parent : parents) {
                                    final TargetGroup foo = new TargetGroup("temporary", parent);
                                    final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
                                    if (target_parent == foo)
                                        log.error("Initial configuration: parent does not exist");
                                    else {
                                        final TargetIPv4 target = new TargetIPv4(
                                                "added by initial configuration",
                                                GenericTools.stringToInet4Address(address), snmp_manager);
                                        target.addTarget(gui, target_parent);
                                        if (subconf.getString("snmp/version") != null) {
                                            if (subconf.getString("snmp/version").equals("v1"))
                                                target.getSNMPQuerier().setVersion(0);
                                            if (subconf.getString("snmp/version").equals("v2c"))
                                                target.getSNMPQuerier().setVersion(1);
                                            if (subconf.getString("snmp/version").equals("v3"))
                                                target.getSNMPQuerier().setVersion(2);
                                        }
                                        if (subconf.getString("snmp/community") != null)
                                            target.getSNMPQuerier()
                                                    .setCommunity(subconf.getString("snmp/community"));

                                        // Setting the agent is not possible when creating a target through the GUI
                                        if (subconf.getString("snmp/agent") != null)
                                            target.getSNMPQuerier().setAddress(GenericTools
                                                    .stringToInet4Address(subconf.getString("snmp/agent")));

                                        if (subconf.getString("snmp/password-auth") != null)
                                            target.getSNMPQuerier()
                                                    .setPasswordAuth(subconf.getString("snmp/password-auth"));
                                        if (subconf.getString("snmp/password-priv") != null)
                                            target.getSNMPQuerier()
                                                    .setPasswordPriv(subconf.getString("snmp/password-priv"));
                                        if (subconf.getString("snmp/pdu-max-size") != null)
                                            target.getSNMPQuerier()
                                                    .setPDUMaxSize(subconf.getInt("snmp/pdu-max-size"));
                                        if (subconf.getString("snmp/port") != null)
                                            target.getSNMPQuerier().setPort(subconf.getInt("snmp/port"));
                                        if (subconf.getString("snmp/retries") != null)
                                            target.getSNMPQuerier().setRetries(subconf.getInt("snmp/retries"));
                                        if (subconf.getString("snmp/security") != null
                                                && subconf.getString("snmp/security").equals("NOAUTH_NOPRIV"))
                                            target.getSNMPQuerier().setSec(SecurityLevel.NOAUTH_NOPRIV);
                                        if (subconf.getString("snmp/security") != null
                                                && subconf.getString("snmp/security").equals("AUTH_NOPRIV"))
                                            target.getSNMPQuerier().setSec(SecurityLevel.AUTH_NOPRIV);
                                        if (subconf.getString("snmp/security") != null
                                                && subconf.getString("snmp/security").equals("AUTH_PRIV"))
                                            target.getSNMPQuerier().setSec(SecurityLevel.AUTH_PRIV);
                                        if (subconf.getString("snmp/timeout") != null)
                                            target.getSNMPQuerier().setTimeout(subconf.getInt("snmp/timeout"));
                                        target.getSNMPQuerier().update();
                                    }
                                }
                        }

                        if (subconf.getProperty("@targetType").equals("ipv6")) {
                            final String address = subconf.getString("address");

                            java.util.List<String> parents = (java.util.List<String>) subconf
                                    .getList("parent[@parentType='group']");
                            if (parents.size() != 0)
                                for (final String parent : parents) {
                                    final TargetGroup foo = new TargetGroup("temporary", parent);
                                    final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
                                    if (target_parent == foo)
                                        log.error("Initial configuration: parent does not exist");
                                    else {
                                        final TargetIPv6 target = new TargetIPv6(
                                                "added by initial configuration",
                                                GenericTools.stringToInet6Address(address), snmp_manager);
                                        target.addTarget(gui, target_parent);
                                    }
                                }
                        }

                        if (subconf.getProperty("@targetType").equals("ipv4range")) {
                            final String begin = subconf.getString("begin");
                            final String end = subconf.getString("end");

                            java.util.List<String> parents = (java.util.List<String>) subconf
                                    .getList("parent[@parentType='group']");
                            if (parents.size() != 0)
                                for (final String parent : parents) {
                                    final TargetGroup foo = new TargetGroup("temporary", parent);
                                    final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
                                    if (target_parent == foo)
                                        log.error("Initial configuration: parent does not exist");
                                    else {
                                        final TargetIPv4Range target = new TargetIPv4Range(
                                                "added by initial configuration",
                                                GenericTools.stringToInet4Address(begin),
                                                GenericTools.stringToInet4Address(end));
                                        target.addTarget(gui, target_parent);
                                    }
                                }
                        }

                        if (subconf.getProperty("@targetType").equals("ipv4subnet")) {
                            final String network = subconf.getString("network");
                            final String netmask = subconf.getString("netmask");

                            java.util.List<String> parents = (java.util.List<String>) subconf
                                    .getList("parent[@parentType='group']");
                            if (parents.size() != 0)
                                for (final String parent : parents) {
                                    final TargetGroup foo = new TargetGroup("temporary", parent);
                                    final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo);
                                    if (target_parent == foo)
                                        log.error("Initial configuration: parent does not exist");
                                    else {
                                        final TargetIPv4Subnet target = new TargetIPv4Subnet(
                                                "added by initial configuration",
                                                GenericTools.stringToInet4Address(network),
                                                GenericTools.stringToInet4Address(netmask));
                                        target.addTarget(gui, target_parent);
                                    }
                                }
                        }
                    }

                    session.getTransaction().commit();
                } catch (final ConfigurationException ex) {
                    log.warn("Exception", ex);
                    session.getTransaction().rollback();
                } catch (final AlgorithmException ex) {
                    log.error("Exception", ex);
                    session.getTransaction().rollback();
                } catch (final UnknownHostException ex) {
                    log.error("Exception", ex);
                    session.getTransaction().rollback();
                }
            }
        }
    });
}

From source file:org.apache.james.fetchmail.ParsedConfiguration.java

protected void configure(HierarchicalConfiguration conf) throws ConfigurationException {
    setHost(conf.getString("host"));

    setFetchTaskName(conf.getString("[@name]"));
    setJavaMailProviderName(conf.getString("javaMailProviderName"));
    setJavaMailFolderName(conf.getString("javaMailFolderName"));
    setRecurse(conf.getBoolean("recursesubfolders"));

    HierarchicalConfiguration recipientNotFound = conf.configurationAt("recipientnotfound");
    setDeferRecipientNotFound(recipientNotFound.getBoolean("[@defer]"));
    setRejectRecipientNotFound(recipientNotFound.getBoolean("[@reject]"));
    setLeaveRecipientNotFound(recipientNotFound.getBoolean("[@leaveonserver]"));
    setMarkRecipientNotFoundSeen(recipientNotFound.getBoolean("[@markseen]"));
    setDefaultDomainName(conf.getString("defaultdomain", "localhost"));

    setFetchAll(conf.getBoolean("fetchall"));

    HierarchicalConfiguration fetched = conf.configurationAt("fetched");
    setLeave(fetched.getBoolean("[@leaveonserver]"));
    setMarkSeen(fetched.getBoolean("[@markseen]"));

    HierarchicalConfiguration remoterecipient = conf.configurationAt("remoterecipient");
    setRejectRemoteRecipient(remoterecipient.getBoolean("[@reject]"));
    setLeaveRemoteRecipient(remoterecipient.getBoolean("[@leaveonserver]"));
    setMarkRemoteRecipientSeen(remoterecipient.getBoolean("[@markseen]"));

    HierarchicalConfiguration blacklist = conf.configurationAt("blacklist");
    setBlacklist(conf.getString("blacklist", ""));
    setRejectBlacklisted(blacklist.getBoolean("[@reject]"));
    setLeaveBlacklisted(blacklist.getBoolean("[@leaveonserver]"));
    setMarkBlacklistedSeen(blacklist.getBoolean("[@markseen]"));

    HierarchicalConfiguration userundefined = conf.configurationAt("userundefined");
    setRejectUserUndefined(userundefined.getBoolean("[@reject]"));
    setLeaveUserUndefined(userundefined.getBoolean("[@leaveonserver]"));
    setMarkUserUndefinedSeen(userundefined.getBoolean("[@markseen]"));

    HierarchicalConfiguration undeliverable = conf.configurationAt("undeliverable");
    setLeaveUndeliverable(undeliverable.getBoolean("[@leaveonserver]"));
    setMarkUndeliverableSeen(undeliverable.getBoolean("[@markseen]"));

    if (conf.getKeys("remotereceivedheader").hasNext()) {
        HierarchicalConfiguration remotereceivedheader = conf.configurationAt("remotereceivedheader");

        setRemoteReceivedHeaderIndex(remotereceivedheader.getInt("[@index]"));
        setRejectRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@reject]"));
        setLeaveRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@leaveonserver]"));
        setMarkRemoteReceivedHeaderInvalidSeen(remotereceivedheader.getBoolean("[@markseen]"));
    }//from w  w w  .ja v  a  2s.co  m

    if (conf.getKeys("maxmessagesize").hasNext()) {
        HierarchicalConfiguration maxmessagesize = conf.configurationAt("maxmessagesize");

        setMaxMessageSizeLimit(maxmessagesize.getInt("[@limit]") * 1024);
        setRejectMaxMessageSizeExceeded(maxmessagesize.getBoolean("[@reject]"));
        setLeaveMaxMessageSizeExceeded(maxmessagesize.getBoolean("[@leaveonserver]"));
        setMarkMaxMessageSizeExceededSeen(maxmessagesize.getBoolean("[@markseen]"));
    }

    if (getLogger().isDebugEnabled()) {
        getLogger().info("Configured FetchMail fetch task " + getFetchTaskName());
    }
}

From source file:org.apereo.lap.model.PipelineConfig.java

public static PipelineConfig makeConfigFromXML(ConfigurationService configurationService,
        StorageService storage, XMLConfiguration xmlConfig) {
    PipelineConfig pc = new PipelineConfig();
    pc.filename = xmlConfig.getFileName();
    pc.name = xmlConfig.getString("name");
    pc.type = xmlConfig.getString("type");
    pc.description = xmlConfig.getString("description");
    // special handling for stats metadata
    HierarchicalConfiguration stats = xmlConfig.configurationAt("stats");
    Iterator<String> statsKeys = stats.getKeys();
    while (statsKeys.hasNext()) {
        String next = statsKeys.next();
        try {/*from   w w w  .j  a va 2  s.  co m*/
            Float f = stats.getFloat(next);
            pc.stats.put(next, f);
        } catch (Exception e) {
            // skip this float and warn
            logger.warn("Unable to get float from " + next + " <stats> field (skipping it): " + e);
        }
    }

    // load the lists
    // sources
    List<HierarchicalConfiguration> sourceFields = xmlConfig.configurationsAt("sources.source");
    for (HierarchicalConfiguration field : sourceFields) {
        try {
            pc.addInputHandlerField(field.getString("type"), field, configurationService, storage);
        } catch (Exception e) {
            // skip this input and warn
            logger.warn("Unable to load input field (" + field.toString() + ") (skipping it): " + e);
        }
    }

    // load the lists
    // inputs
    List<HierarchicalConfiguration> inputFields = xmlConfig.configurationsAt("inputs.fields.field");
    for (HierarchicalConfiguration field : inputFields) {
        try {
            pc.addInputField(InputField.make(field.getString("name"), field.getBoolean("required", false)));
        } catch (Exception e) {
            // skip this input and warn
            logger.warn("Unable to load input field (" + field.toString() + ") (skipping it): " + e);
        }
    }
    // processors
    List<HierarchicalConfiguration> processors = xmlConfig.configurationsAt("processors.processor");
    for (HierarchicalConfiguration processor : processors) {
        try {
            String pType = processor.getString("type");
            Processor.ProcessorType pt = Processor.ProcessorType.fromString(pType); // IllegalArgumentException if invalid
            if (pt == Processor.ProcessorType.KETTLE_JOB) {
                pc.addProcessor(
                        Processor.makeKettleJob(processor.getString("name"), processor.getString("file")));
            } else if (pt == Processor.ProcessorType.KETTLE_TRANSFORM) {
                pc.addProcessor(Processor.makeKettleTransform(processor.getString("name"),
                        processor.getString("file")));
            } else if (pt == Processor.ProcessorType.KETTLE_DATA) {
                Processor p = new Processor();
                p.type = Processor.ProcessorType.KETTLE_DATA;
                p.name = processor.getString("name");
                p.count = processor.getInt("count");
                pc.addProcessor(p);
                logger.warn("KETTLE DATA processor loaded (" + p.toString() + ")");
            } // Add other types here as needed
        } catch (Exception e) {
            // skip this processor and warn
            logger.warn("Unable to load processor (" + processor.toString() + ") (skipping it): " + e);
        }
    }
    // outputs
    List<HierarchicalConfiguration> outputs = xmlConfig.configurationsAt("outputs.output");
    for (HierarchicalConfiguration output : outputs) {

        // TODO - we need to rethink output handling
        // don't want to add code every time we need to support a new output type
        try {
            String oType = output.getString("type");
            Output.OutputType ot = Output.OutputType.fromString(oType); // IllegalArgumentException if invalid
            if (ot == Output.OutputType.CSV) {
                Output o = Output.makeCSV(output.getString("from"), output.getString("filename"));
                // load the output fields
                List<HierarchicalConfiguration> outputFields = output.configurationsAt("fields.field");
                for (HierarchicalConfiguration outputField : outputFields) {
                    o.addFieldCSV(outputField.getString("source"), outputField.getString("header"));
                }
                pc.addOutput(o);
            } else if (ot == Output.OutputType.STORAGE) {
                Output o = Output.makeStorage(output.getString("from"), output.getString("to"));
                // load the output fields
                List<HierarchicalConfiguration> outputFields = output.configurationsAt("fields.field");
                for (HierarchicalConfiguration outputField : outputFields) {
                    o.addFieldStorage(outputField.getString("source"), outputField.getString("target"));
                }
                pc.addOutput(o);
            } else if (ot == Output.OutputType.SSPEARLYALERT) {
                Output o = new Output();
                o.type = Output.OutputType.SSPEARLYALERT;
                o.from = output.getString("from");
                o.to = output.getString("to");

                List<HierarchicalConfiguration> outputFields = output.configurationsAt("fields.field");
                for (HierarchicalConfiguration outputField : outputFields) {
                    OutputField field = new OutputField(o.type, outputField.getString("source"),
                            outputField.getString("target"), null);
                    o.fields.add(field);
                }
                pc.addOutput(o);
            }
            // Add other types here as needed
        } catch (Exception e) {
            // skip this processor and warn
            logger.warn("Unable to load output (" + output.toString() + ") (skipping it): " + e);
        }
    }
    return pc;
}

From source file:org.bgp4j.config.nodes.impl.PeerConfigurationParser.java

public PeerConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException {
    PeerConfigurationImpl peerConfig = new PeerConfigurationImpl();
    List<HierarchicalConfiguration> clientConfigs = config.configurationsAt("Client");
    List<HierarchicalConfiguration> capabilityConfigs = config.configurationsAt("Capabilities");

    try {/*from  w  w w.  jav a 2  s  .c  o  m*/
        peerConfig.setPeerName(config.getString("[@name]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("peer name not set", e);
    }

    if (clientConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Client/> element");
    } else if (clientConfigs.size() == 0) {
        throw new ConfigurationException("missing <Client/> element");
    } else
        peerConfig.setClientConfig(clientConfigurationParser.parseConfig(clientConfigs.get(0)));

    if (capabilityConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Capabilities/> element");
    } else if (capabilityConfigs.size() == 1)
        peerConfig.setCapabilities(capabilityParser.parseConfig(capabilityConfigs.get(0)));

    try {
        peerConfig.setLocalAS(config.getInt("AutonomousSystem[@local]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local AS number not given", e);
    }
    try {
        peerConfig.setRemoteAS(config.getInt("AutonomousSystem[@remote]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote AS number not given", e);
    }

    try {
        long identifier = config.getLong("BgpIdentifier[@local]");

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid local BGP identifier: " + identifier);

        peerConfig.setLocalBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local BGP identifier not given", e);
    }
    try {
        long identifier = config.getLong("BgpIdentifier[@remote]");

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid remote BGP identifier: " + identifier);

        peerConfig.setRemoteBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote BGP identifier not given", e);
    }

    peerConfig.setHoldTime(config.getInt("Timers[@holdTime]", 0));
    peerConfig.setIdleHoldTime(config.getInt("Timers[@idleHoldTime]", 0));
    peerConfig.setDelayOpenTime(config.getInt("Timers[@delayOpenTime]", 0));
    peerConfig.setConnectRetryTime(config.getInt("Timers[@connectRetryTime]", 0));
    peerConfig.setAutomaticStartInterval(config.getInt("Timers[@automaticStartInterval]", 0));

    peerConfig.setAllowAutomaticStart(config.getBoolean("Options[@allowAutomaticStart]", true));
    peerConfig.setAllowAutomaticStop(config.getBoolean("Options[@allowAutomaticStop]", false));
    peerConfig.setDampPeerOscillation(config.getBoolean("Options[@dampPeerOscillation]", false));
    peerConfig.setCollisionDetectEstablishedState(
            config.getBoolean("Options[@collisionDetectEstablishedState]", false));
    peerConfig.setDelayOpen(config.getBoolean("Options[@delayOpen]", false));
    peerConfig.setPassiveTcpEstablishment(config.getBoolean("Options[@passiveTcpEstablishment]", false));
    peerConfig.setHoldTimerDisabled(config.getBoolean("Options[@holdTimerDisabled]", false));

    return peerConfig;
}

From source file:org.nnsoft.t2t.configuration.ConfigurationManager.java

private MigratorConfiguration.ConnectionParameter getDestinationConnection(XMLConfiguration xmlConfiguration) {
    HierarchicalConfiguration destination = xmlConfiguration.configurationAt("destination");
    HierarchicalConfiguration connection = destination.configurationAt("connection");
    String host = connection.getString("host");
    int port = connection.getInt("port");
    String user = connection.getString("username");
    String passwd = connection.getString("password");
    return new MigratorConfiguration.ConnectionParameter(host, port, user, passwd);
}

From source file:org.nnsoft.t2t.configuration.ConfigurationManager.java

private MigratorConfiguration.ConnectionParameter getSourceConnection(XMLConfiguration xmlConfiguration) {
    HierarchicalConfiguration source = xmlConfiguration.configurationAt("source");
    HierarchicalConfiguration connection = source.configurationAt("connection");
    String host = connection.getString("host");
    int port = connection.getInt("port");
    String user = connection.getString("username");
    String passwd = connection.getString("password");
    return new MigratorConfiguration.ConnectionParameter(host, port, user, passwd);
}

From source file:org.onosproject.drivers.juniper.JuniperUtils.java

/**
 * Parses neighbours discovery information and returns a list of
 * link abstractions./*  w ww  .  ja v  a2 s  . c  om*/
 *
 * @param info interface configuration
 * @return set of link abstractions
 */
public static Set<LinkAbstraction> parseJuniperLldp(HierarchicalConfiguration info) {
    Set<LinkAbstraction> neighbour = new HashSet<>();
    List<HierarchicalConfiguration> subtrees = info.configurationsAt(LLDP_NBR_INFO);
    for (HierarchicalConfiguration neighborsInfo : subtrees) {
        List<HierarchicalConfiguration> neighbors = neighborsInfo.configurationsAt(LLDP_NBR_INFO);
        for (HierarchicalConfiguration neighbor : neighbors) {
            String localPortName = neighbor.getString(LLDP_LO_PORT);
            MacAddress mac = MacAddress.valueOf(neighbor.getString(LLDP_REM_CHASS));
            int remotePortIndex = neighbor.getInt(LLDP_REM_PORT);
            LinkAbstraction link = new LinkAbstraction(localPortName, mac.toLong(), remotePortIndex);
            neighbour.add(link);
        }
    }
    return neighbour;
}

From source file:org.onosproject.drivers.oplink.OplinkOpticalFlowRuleProgrammable.java

private FlowRule parseConnection(HierarchicalConfiguration cfg) {
    return OplinkOpticalUtility.toFlowRule(this, PortNumber.portNumber(cfg.getString(KEY_SRC_PORTID)),
            PortNumber.portNumber(cfg.getString(KEY_DST_PORTID)), cfg.getInt(KEY_SRC_CHID));

}