Java Code Examples for org.apache.commons.configuration.HierarchicalConfiguration#getString()

The following examples show how to use org.apache.commons.configuration.HierarchicalConfiguration#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LPlatformBase.java    From development with Apache License 2.0 6 votes vote down vote up
public List<Network> getNetworks() {
    List<Network> result = new LinkedList<Network>();
    if (configuration != null) {
        List<HierarchicalConfiguration> networks = configuration
                .configurationsAt("networks.network");
        for (HierarchicalConfiguration networkEntry : networks) {
            int maxVm = 0;
            try {
                maxVm = Integer.parseInt(networkEntry
                        .getString("numOfMaxVm"));
            } catch (NumberFormatException e) {
                maxVm = Integer.MAX_VALUE;
            }
            Network network = new Network(networkEntry.getString("name"),
                    networkEntry.getString("networkCategory"),
                    networkEntry.getString("networkId"), maxVm);
            result.add(network);
        }
    }
    return result;
}
 
Example 2
Source File: PolatisDeviceDescription.java    From onos with Apache License 2.0 6 votes vote down vote up
private DeviceDescription parseProductInformation() {
    DeviceService devsvc = checkNotNull(handler().get(DeviceService.class));
    DeviceId devid = handler().data().deviceId();
    Device dev = devsvc.getDevice(devid);
    if (dev == null) {
        return new DefaultDeviceDescription(devid.uri(), FIBER_SWITCH,
                DEFAULT_MANUFACTURER, DEFAULT_DESCRIPTION_DATA,
                DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA,
                new ChassisId());
    }
    String reply = netconfGet(handler(), getProductInformationFilter());
    subscribe(handler());
    HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF);
    return new DefaultDeviceDescription(dev.id().uri(), FIBER_SWITCH,
            cfg.getString(KEY_MANUFACTURER), cfg.getString(KEY_HWVERSION),
            cfg.getString(KEY_SWVERSION), cfg.getString(KEY_SERIALNUMBER),
            dev.chassisId());
}
 
Example 3
Source File: EncoderConfig.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private static List<TabModel> loadConfig(ZapXmlConfiguration config) {
    List<TabModel> tabs = new ArrayList<>();
    List<HierarchicalConfiguration> tabConfigs = config.configurationsAt(TAB_PATH);
    for (HierarchicalConfiguration tabConfig : tabConfigs) {
        String tabName = tabConfig.getString(TAB_NAME_KEY);
        TabModel tab = new TabModel();
        tab.setName(tabName);

        List<OutputPanelModel> panels = new ArrayList<>();
        List<HierarchicalConfiguration> panelConfigs =
                tabConfig.configurationsAt(OUTPUT_PANEL_PATH);
        for (HierarchicalConfiguration panelConfig : panelConfigs) {
            String panelName = panelConfig.getString(OUTPUT_PANEL_NAME_KEY);
            String script = panelConfig.getString(OUTPUT_PANEL_SCRIPT_KEY);
            OutputPanelModel panel = new OutputPanelModel();
            panel.setName(panelName);
            panel.setProcessorId(script);
            panels.add(panel);
        }

        tab.setOutputPanels(panels);
        tabs.add(tab);
    }
    return tabs;
}
 
Example 4
Source File: TerminalDevicePowerConfig.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * mirror method in the internal class.
 *
 * @param port      port
 * @param component the component
 * @return current input power
 */
public Optional<Double> currentInputPower(PortNumber port, Object component) {
    Map<String, String> rpcMap = driver.buildRpcString(CURRENT_INPUT_POWER);
    String configString = rpcMap.get("CURRENT_INPUT_POWER_PATH"),
            queryStr = rpcMap.get("CURRENT_INPUT_POWER_ROUTE"),
            paramStr = rpcMap.get("CURRENT_INPUT_POWER_LEAF");
    XMLConfiguration xconf = getOpticalChannelState(
            driver, port, queryStr);
    try {
        HierarchicalConfiguration config =
                xconf.configurationAt(configString);
        if (config == null || config.getString(paramStr) == null) {
            return Optional.empty();
        }
        double currentPower = Float.valueOf(config.getString(paramStr)).doubleValue();
        return Optional.of(currentPower);
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 5
Source File: DomainController.java    From wings with Apache License 2.0 6 votes vote down vote up
private void initializeDomainList(String domname) {
	PropertyListConfiguration config = this.getUserConfiguration();
	List<HierarchicalConfiguration> domnodes = config.configurationsAt("user.domains.domain");
	if(domname == null)
	  domname= config.getString("user.domain");
	for (HierarchicalConfiguration domnode : domnodes) {
		String domurl = domnode.getString("url");
		Boolean isLegacy = domnode.getBoolean("legacy", false);
		String dname = domnode.getString("name");
		Domain domain = new Domain(dname, domnode.getString("dir"), domurl, isLegacy);
		if(dname.equals(domname)) 
			this.domain = domain;
		DomainInfo dominfo = new DomainInfo(domain);
		this.user_domains.put(dominfo.getName(), dominfo);
	}
}
 
Example 6
Source File: PolatisAlarmConsumer.java    From onos with Apache License 2.0 5 votes vote down vote up
private Alarm parseAlarm(HierarchicalConfiguration cfg) {
    boolean cleared = false;
    String alarmType = cfg.getString(ALARM_TYPE);
    String alarmMessage = cfg.getString(ALARM_MESSAGE);
    SeverityLevel alarmLevel = SeverityLevel.INDETERMINATE;
    if (alarmType.equals(ALARM_TYPE_LOS)) {
        alarmLevel = SeverityLevel.MAJOR;
    }
    long timeRaised = getTimeRaised(cfg);
    DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(
            AlarmId.alarmId(deviceId, alarmMessage),
            deviceId, alarmMessage, alarmLevel, timeRaised);
    return alarmBuilder.build();
}
 
Example 7
Source File: StorageBalancer.java    From development with Apache License 2.0 5 votes vote down vote up
@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());
        }
    }
}
 
Example 8
Source File: MyConfigurationXMLUtils.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 获取树状结构数据
 */
public void getHierarchicalExample() {

    try {
        XMLConfiguration config = new XMLConfiguration("properties-website-job.xml");
        log.info(config.getFileName());
        //   log.info(config.getStringByEncoding("jdbc.oracle.work.235.url", "GBK"));

        //包含 websites.site.name 的集合
        Object prop = config.getProperty("websites.site.name");

        if (prop instanceof Collection) {
            //  System.out.println("Number of tables: " + ((Collection<?>) prop).size());
            Collection<String> c = (Collection<String>) prop;
            int i = 0;

            for (String s : c) {

                System.out.println("sitename :" + s);

                List<HierarchicalConfiguration> fields = config.configurationsAt("websites.site(" + String.valueOf(i) + ").fields.field");
                for (HierarchicalConfiguration sub : fields) {
                    // sub contains all data about a single field
                    //此处可以包装成 bean
                    String name = sub.getString("name");
                    String type = sub.getString("type");
                    System.out.println("name :" + name + " , type :" + type);
                }

                i++;
                System.out.println(" === ");
            }
        }
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }


}
 
Example 9
Source File: OpenconfigBitErrorRateState.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the BER value pre FEC.
 *
 * @param deviceId the device identifier
 * @param port     the port identifier
 * @return the decimal value of BER
 */
@Override
public Optional<Double> getPreFecBer(DeviceId deviceId, PortNumber port) {
    NetconfSession session = NetconfSessionUtility
            .getNetconfSession(deviceId, getController());
    checkNotNull(session);

    String preFecBerFilter = generateBerFilter(deviceId, port, PRE_FEC_BER_TAG);
    String rpcRequest = getConfigOperation(preFecBerFilter);
    log.debug("RPC call for fetching Pre FEC BER : {}", rpcRequest);

    XMLConfiguration xconf = NetconfSessionUtility.executeRpc(session, rpcRequest);

    if (xconf == null) {
        log.error("Error in executing Pre FEC BER RPC");
        return Optional.empty();
    }

    try {
        HierarchicalConfiguration config =
                xconf.configurationAt("data/components/component/transceiver/state/" + PRE_FEC_BER_TAG);
        if (config == null || config.getString("instant") == null) {
            return Optional.empty();
        }
        double ber = Float.valueOf(config.getString("instant")).doubleValue();
        return Optional.of(ber);

    } catch (IllegalArgumentException e) {
        log.error("Error in fetching configuration : {}", e.getMessage());
        return Optional.empty();
    }
}
 
Example 10
Source File: TCPIPProxySettings.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public void load(HierarchicalConfiguration config)
{
	this.host = config.getString("host");
	this.port = config.getInt("port");
	this.listenPort = config.getInt("listenPort");
	this.codecClassName = config.getString("codecClass");
	this.timeout = config.getLong("timeout");
}
 
Example 11
Source File: JuniperUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses neighbours discovery information and returns a list of
 * link abstractions.
 *
 * @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_LIST_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));
            String remotePortId = null;
            long remotePortIndex = -1;
            String remotePortIdSubtype = neighbor.getString(LLDP_REM_PORT_SUBTYPE, null);
            if (remotePortIdSubtype != null) {
                if (remotePortIdSubtype.equals(LLDP_SUBTYPE_MAC)
                        || remotePortIdSubtype.equals(LLDP_SUBTYPE_INTERFACE_NAME)) {
                    remotePortId = neighbor.getString(LLDP_REM_PORT, null);
                } else {
                    remotePortIndex = neighbor.getLong(LLDP_REM_PORT, -1);
                }
            }
            String remotePortDescription = neighbor.getString(LLDP_REM_PORT_DES, null);
            LinkAbstraction link = new LinkAbstraction(
                    localPortName,
                    mac.toLong(),
                    remotePortIndex,
                    remotePortId,
                    remotePortDescription);
            neighbour.add(link);
        }
    }
    return neighbour;
}
 
Example 12
Source File: TerminalDevicePowerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * mirror method in the internal class.
 *
 * @param port      port
 * @param component component
 * @return target power
 */
public Optional<Double> getTargetPower(PortNumber port, Object component) {
    NetconfSession session = driver.getNetconfSession(driver.did(), "", "");
    checkNotNull(session);
    String filter = parsePort(driver, port, null, null);
    StringBuilder rpcReq = new StringBuilder();
    rpcReq.append(RPC_TAG_NETCONF_BASE)
            .append(driver.getTargetPowerRequestRpc(filter))
            .append(RPC_CLOSE_TAG);
    XMLConfiguration xconf = driver.executeRpc(session, rpcReq.toString());
    if (xconf == null) {
        log.error("Error in executingRpc");
        return Optional.empty();
    }
    try {
        Map<String, String> rpcMap = driver.buildRpcString(TARGET_POWER);
        String configString = rpcMap.get("TARGET_OUTPUT_PATH"),
                paramStr = rpcMap.get("TARGET_OUTPUT_LEAF");
        HierarchicalConfiguration config =
                xconf.configurationAt(configString);
        if (config == null || config.getString(paramStr) == null) {
            return Optional.empty();
        }
        double power = Float.valueOf(config.getString(paramStr)).doubleValue();
        return Optional.of(power);
    } catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example 13
Source File: LPlatformConfiguration.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getServerStatus() {
    List<String> result = new LinkedList<String>();
    if (configuration != null) {
        List<HierarchicalConfiguration> servers = configuration
                .configurationsAt("lservers.lserver");
        for (HierarchicalConfiguration server : servers) {
            String status = server.getString("lserverStatus");
            if (status != null && status.trim().length() > 0) {
                result.add(status);
            }
        }
    }
    return result;
}
 
Example 14
Source File: ScriptSettings.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private void loadProperties(HierarchicalConfiguration config)
{
	Iterator<?> it = config.getKeys();

	while (it.hasNext())
	{
	    String key = (String)it.next();
	    String value = config.getString(key);
	    
	    properties.put(key, value);
	}
}
 
Example 15
Source File: ZteDeviceDiscoveryImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isPortComponent(HierarchicalConfiguration component) {
    String name = component.getString("name");
    String type = component.getString("state/type");

    return name != null && name.startsWith("PORT") && type != null
            && type.equals("openconfig-platform-types:PORT");
}
 
Example 16
Source File: AdapterDescription.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public void load(HierarchicalConfiguration config) 
{
	this.adapterForClass = config.getString("AdapterForClass");
    this.adapterClass = config.getString("AdapterClass");
    this.adapterClassImpl = config.getString("AdapterClassImpl");
}
 
Example 17
Source File: PolatisAlarmConsumer.java    From onos with Apache License 2.0 4 votes vote down vote up
private long getTimeRaised(HierarchicalConfiguration cfg) {
    String alarmTime = cfg.getString(ALARM_TIME);
    return XmlEventParser.getEventTime(alarmTime);
}
 
Example 18
Source File: XmlParserCisco.java    From onos with Apache License 2.0 4 votes vote down vote up
private static String getInterfaceName(HierarchicalConfiguration intfConfig) {
    return intfConfig.getString("Param");
}
 
Example 19
Source File: AbstractServiceSettings.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public void load(HierarchicalConfiguration cfg) {
	this.expectedTimeOfStarting = cfg.getLong("expectedTimeOfStarting", 0L);
	this.waitingTimeBeforeStarting = cfg.getLong("waitingTimeBeforeStarting", 0L);
	this.comment = cfg.getString("comment", null);
}
 
Example 20
Source File: EnvironmentSettings.java    From sailfish-core with Apache License 2.0 3 votes vote down vote up
private void loadGeneralSettings(HierarchicalConfiguration config) {
	this.fileStoragePath = config.getString("FileStoragePath", "storage");

	this.storeAdminMessages = config.getBoolean("StoreAdminMessages", true);

	this.asyncRunMatrix = config.getBoolean(ASYNC_RUN_MATRIX_KEY, false);

	this.maxQueueSize = config.getLong(MAX_STORAGE_QUEUE_SIZE, 1024*1024*512);

	this.storageType = StorageType.parse(config.getString("StorageType", StorageType.DB.getName()));

       this.comparisonPrecision = config.getBigDecimal(COMPARISON_PRECISION, MathProcessor.COMPARISON_PRECISION);
}