Java源码示例:org.apache.commons.configuration.tree.xpath.XPathExpressionEngine
示例1
/**
* 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();
}
}
示例2
/**
* 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();
}
}
示例3
/**
* 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();
}
}
示例4
/**
* 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();
}
}
示例5
/**
* 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;
}
示例6
/**
* 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();
}
}
示例7
/**
*
* @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);
}
}
示例8
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.
}
示例9
/**
* 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();
}
}
示例10
/**
* 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();
}
}
示例11
/**
* 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());
}
示例12
/**
* 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());
}
示例13
/**
* 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());
}
示例14
/**
* 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());
}
示例15
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());
}
示例16
/**
* 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();
}
}