本文整理了Java中org.opendaylight.controller.netconf.util.xml.XmlElement.getOnlyChildElementOptionally()
方法的一些代码示例,展示了XmlElement.getOnlyChildElementOptionally()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlElement.getOnlyChildElementOptionally()
方法的具体详情如下:
包路径:org.opendaylight.controller.netconf.util.xml.XmlElement
类名称:XmlElement
方法名:getOnlyChildElementOptionally
暂无
代码示例来源:origin: org.opendaylight.controller/config-netconf-connector
private static Optional<XmlElement> getServicesElement(XmlElement xml) {
return xml.getOnlyChildElementOptionally(XmlNetconfConstants.SERVICES_KEY,
XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
}
代码示例来源:origin: org.opendaylight.controller/config-netconf-connector
private static Optional<XmlElement> getModulesElement(XmlElement xml) {
return xml.getOnlyChildElementOptionally(XmlNetconfConstants.MODULES_KEY,
XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
}
代码示例来源:origin: org.opendaylight.controller/mdsal-netconf-connector
private XmlElement getElement(final XmlElement operationElement, String elementName) throws NetconfDocumentedException {
final Optional<XmlElement> childNode = operationElement.getOnlyChildElementOptionally(elementName);
if (!childNode.isPresent()) {
throw new NetconfDocumentedException(elementName + " element is missing",
ErrorType.protocol,
ErrorTag.missing_element,
ErrorSeverity.error);
}
return childNode.get();
}
代码示例来源:origin: org.opendaylight.controller/mdsal-netconf-connector
private static Optional<Datastore> parseSource(final XmlElement xml) throws NetconfDocumentedException {
final Optional<XmlElement> sourceElement = xml.getOnlyChildElementOptionally(XmlNetconfConstants.SOURCE_KEY,
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
return sourceElement.isPresent() ?
Optional.of(Datastore.valueOf(sourceElement.get().getOnlyChildElement().getName())) : Optional.<Datastore>absent();
}
代码示例来源:origin: org.opendaylight.controller/mdsal-netconf-connector
/**
*
* @param operationElement operation element
* @return if Filter is present and not empty returns Optional of the InstanceIdentifier to the read location in datastore.
* empty filter returns Optional.absent() which should equal an empty <data/> container in the response.
* if filter is not present we want to read the entire datastore - return ROOT.
* @throws NetconfDocumentedException
*/
protected Optional<YangInstanceIdentifier> getDataRootFromFilter(XmlElement operationElement) throws NetconfDocumentedException {
Optional<XmlElement> filterElement = operationElement.getOnlyChildElementOptionally(FILTER);
if (filterElement.isPresent()) {
if (filterElement.get().getChildElements().size() == 0) {
return Optional.absent();
}
return Optional.of(getInstanceIdentifierFromFilter(filterElement.get()));
} else {
return Optional.of(ROOT);
}
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public Optional<XmlElement> getOnlyChildElementWithSameNamespaceOptionally() {
Optional<XmlElement> child = getOnlyChildElementOptionally();
if (child.isPresent()
&& child.get().getNamespaceOptionally().isPresent()
&& getNamespaceOptionally().isPresent()
&& getNamespaceOptionally().get().equals(child.get().getNamespaceOptionally().get())) {
return child;
}
return Optional.absent();
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public static Collection<String> extractCapabilitiesFromHello(Document doc) throws NetconfDocumentedException {
XmlElement responseElement = XmlElement.fromDomDocument(doc);
// Extract child element <capabilities> from <hello> with or without(fallback) the same namespace
Optional<XmlElement> capabilitiesElement = responseElement
.getOnlyChildElementWithSameNamespaceOptionally(XmlNetconfConstants.CAPABILITIES)
.or(responseElement
.getOnlyChildElementOptionally(XmlNetconfConstants.CAPABILITIES));
List<XmlElement> caps = capabilitiesElement.get().getChildElements(XmlNetconfConstants.CAPABILITY);
return Collections2.transform(caps, new Function<XmlElement, String>() {
@Override
public String apply(@Nonnull XmlElement input) {
// Trim possible leading/tailing whitespace
try {
return input.getTextContent().trim();
} catch (NetconfDocumentedException e) {
LOG.trace("Error fetching input text content",e);
return null;
}
}
});
}
}
代码示例来源:origin: org.opendaylight.controller/netconf-impl
static Document applySubtreeFilter(Document requestDocument, Document rpcReply) throws NetconfDocumentedException {
OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(requestDocument);
if (XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(operationNameAndNamespace.getNamespace()) &&
XmlNetconfConstants.GET.equals(operationNameAndNamespace.getOperationName()) ||
XmlNetconfConstants.GET_CONFIG.equals(operationNameAndNamespace.getOperationName())) {
// process subtree filtering here, in case registered netconf operations do
// not implement filtering.
Optional<XmlElement> maybeFilter = operationNameAndNamespace.getOperationElement().getOnlyChildElementOptionally(
XmlNetconfConstants.FILTER, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
if (!maybeFilter.isPresent()) {
return rpcReply;
}
// FIXME: rpcReply document must be reread otherwise some nodes do not inherit namespaces. (services/service)
try {
rpcReply = XmlUtil.readXmlToDocument(XmlUtil.toString(rpcReply, true));
} catch (SAXException | IOException e) {
LOG.error("Cannot transform document", e);
throw new NetconfDocumentedException("Cannot transform document" + e);
}
XmlElement filter = maybeFilter.get();
if ("subtree".equals(filter.getAttribute("type"))||
"subtree".equals(filter.getAttribute("type", XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0))) {
// do
return filtered(maybeFilter.get(), rpcReply);
}
}
return rpcReply; // return identical document
}
代码示例来源:origin: org.opendaylight.controller/config-netconf-connector
.getOnlyChildElementOptionally(CONTEXT_INSTANCE);
内容来源于网络,如有侵权,请联系作者删除!