org.apache.commons.configuration.tree.xpath.XPathExpressionEngine Java Examples

The following examples show how to use org.apache.commons.configuration.tree.xpath.XPathExpressionEngine. 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: AdvaTerminalDeviceDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getTerminalDeviceBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());

        HierarchicalConfiguration logicalChannels = xconf.configurationAt("data/terminal-device/logical-channels");
        return parseLogicalChannels(logicalChannels);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example #2
Source File: ClientLineTerminalDeviceDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        XPathExpressionEngine xpe = new XPathExpressionEngine();
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getDeviceComponentsBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(xpe);

        log.debug("REPLY {}", rpcReply);
        HierarchicalConfiguration components = xconf.configurationAt("data/components");
        return parsePorts(components);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example #3
Source File: TerminalDeviceDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        XPathExpressionEngine xpe = new XPathExpressionEngine();
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getDeviceComponentsBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(xpe);

        HierarchicalConfiguration components = xconf.configurationAt("data/components");
        return parsePorts(components);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example #4
Source File: CassiniTerminalDeviceDiscoveryOld.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getTerminalDeviceBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());

        HierarchicalConfiguration logicalChannels = xconf.configurationAt("data/terminal-device/logical-channels");
        return parseLogicalChannels(logicalChannels);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example #5
Source File: CassiniTerminalDevicePowerConfigExt.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Execute RPC request.
 * @param session Netconf session
 * @param message Netconf message in XML format
 * @return XMLConfiguration object
 */
private XMLConfiguration executeRpc(NetconfSession session, String message) {
    try {
        CompletableFuture<String> fut = session.rpc(message);
        String rpcReply = fut.get();
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());
        return xconf;
    } catch (NetconfException ne) {
        log.error("Exception on Netconf protocol: {}.", ne);
    } catch (InterruptedException ie) {
        log.error("Interrupted Exception: {}.", ie);
    } catch (ExecutionException ee) {
        log.error("Concurrent Exception while executing Netconf operation: {}.", ee);
    }
    return null;
}
 
Example #6
Source File: GrooveOpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }

        CompletableFuture<String> fut = session.rpc(getTerminalDeviceBuilder());
        String rpcReply = fut.get();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());

        HierarchicalConfiguration logicalChannels = xconf.configurationAt("data/terminal-device/logical-channels");
        return parseLogicalChannels(logicalChannels);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
 
Example #7
Source File: XPathUtils.java    From qaf with MIT License 5 votes vote down vote up
/**
 * 
 * @param src
 * @return
 */
public static XMLConfiguration read(String src) {
	try {
		// remove all namespaces from xml
		src = removeNSAndPreamble(src);
		XMLConfiguration config = new XMLConfiguration();
		config.setDelimiterParsingDisabled(true);
		config.load(new ByteArrayInputStream(src.getBytes()));
		config.setExpressionEngine(new XPathExpressionEngine());
		return config;

	} catch (ConfigurationException e) {
		throw new RuntimeException(e);
	}
}
 
Example #8
Source File: ConfigurationEditor.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public ConfigurationEditor(String originalConfigFilePath) throws ConfigurationException {
    this.originalConfigFilePath = originalConfigFilePath;

    configuration = new XMLConfiguration(this.originalConfigFilePath);

    // Support XPath queries.
    configuration.setExpressionEngine(new XPathExpressionEngine());

    configuration.setDelimiterParsingDisabled(true); // If we don't do this,
    // we can't add a new configuration to the compositeConfiguration by code.
}
 
Example #9
Source File: OpenRoadmDeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the external links as a list of XML hieriarchical configs.
 *  @param session the NETConf session to the OpenROADM device.
 *  @return a list of hierarchical conf. each one external link.
 */
List<HierarchicalConfiguration> getExternalLinks(NetconfSession session) {
    try {
        String reply = session.rpc(getDeviceExternalLinksBuilder()).get();
        XMLConfiguration extLinksConf = //
            (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        extLinksConf.setExpressionEngine(new XPathExpressionEngine());
        return extLinksConf.configurationsAt(
                "/data/org-openroadm-device/external-link");
    } catch (NetconfException | InterruptedException | ExecutionException e) {
        log.error("[OPENROADM] {} exception getting external links", did());
        return ImmutableList.of();
    }
}
 
Example #10
Source File: OpenRoadmDeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the circuit packs from the device as a list of XML hierarchical configs.
 *  @param session the NETConf session to the OpenROADM device.
 *  @return a list of hierarchical conf. each one circuit pack.
 */
List<HierarchicalConfiguration> getCircuitPacks(NetconfSession session) {
    try {
        String reply = session.rpc(getDeviceCircuitPacksBuilder()).get();
        XMLConfiguration cpConf = //
            (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        cpConf.setExpressionEngine(new XPathExpressionEngine());
        return cpConf.configurationsAt(
                "/data/org-openroadm-device/circuit-packs");
    } catch (NetconfException | InterruptedException | ExecutionException e) {
        log.error("[OPENROADM] {} exception getting circuit packs", did());
        return ImmutableList.of();
    }
}
 
Example #11
Source File: NokiaOpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
private List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());
    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
            .map(this::toPortDescriptionInternal)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #12
Source File: OpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
protected List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());

    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
        .map(this::toPortDescription)
        .filter(Objects::nonNull)
        .collect(Collectors.toList());
}
 
Example #13
Source File: InfineraOpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
protected List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());

    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("interfaces/interface");
    return components.stream()
            .map(this::toPortDescription)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #14
Source File: CassiniTerminalDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
private List<PortDescription> discoverPorts(HierarchicalConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());
    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("component");
    return components.stream()
            .map(this::toPortDescriptionInternal)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #15
Source File: ZteDeviceDiscoveryImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    cfg.setExpressionEngine(new XPathExpressionEngine());
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
            .filter(this::isPortComponent)
            .map(this::toPortDescriptionInternal)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #16
Source File: CassiniTerminalDeviceDiscovery.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 * <p>
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }
        CompletableFuture<CharSequence> fut1 = session.asyncGet();
        String rpcReplyTest = fut1.get().toString();

        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReplyTest);
        xconf.setExpressionEngine(new XPathExpressionEngine());

        HierarchicalConfiguration logicalChannels = xconf.configurationAt("components");
        return discoverPorts(logicalChannels);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}