本文整理了Java中org.opendaylight.controller.netconf.util.xml.XmlElement.getChildElements()
方法的一些代码示例,展示了XmlElement.getChildElements()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlElement.getChildElements()
方法的具体详情如下:
包路径:org.opendaylight.controller.netconf.util.xml.XmlElement
类名称:XmlElement
方法名:getChildElements
暂无
代码示例来源:origin: org.opendaylight.controller/netconf-impl
private static void addSubtree(XmlElement filter, XmlElement src, XmlElement dst) throws NetconfDocumentedException {
for (XmlElement srcChild : src.getChildElements()) {
for (XmlElement filterChild : filter.getChildElements()) {
addSubtree2(filterChild, srcChild, dst);
}
}
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public Optional<XmlElement> getOnlyChildElementOptionally(String childName) {
List<XmlElement> nameElements = getChildElements(childName);
if (nameElements.size() != 1) {
return Optional.absent();
}
return Optional.of(nameElements.get(0));
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public Optional<XmlElement> getOnlyChildElementOptionally() {
List<XmlElement> children = getChildElements();
if (children.size() != 1) {
return Optional.absent();
}
return Optional.of(children.get(0));
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public void checkUnrecognisedElements(List<XmlElement> recognisedElements,
XmlElement... additionalRecognisedElements) throws NetconfDocumentedException {
List<XmlElement> childElements = getChildElements();
childElements.removeAll(recognisedElements);
for (XmlElement additionalRecognisedElement : additionalRecognisedElements) {
childElements.remove(additionalRecognisedElement);
}
if (!childElements.isEmpty()){
throw new NetconfDocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
NetconfDocumentedException.ErrorType.application,
NetconfDocumentedException.ErrorTag.invalid_value,
NetconfDocumentedException.ErrorSeverity.error);
}
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public XmlElement getOnlyChildElement() throws NetconfDocumentedException {
List<XmlElement> children = getChildElements();
if (children.size() != 1){
throw new NetconfDocumentedException(String.format( "One element expected in %s but was %s", toString(),
children.size()),
NetconfDocumentedException.ErrorType.application,
NetconfDocumentedException.ErrorTag.invalid_value,
NetconfDocumentedException.ErrorSeverity.error);
}
return children.get(0);
}
代码示例来源:origin: org.opendaylight.controller/config-netconf-connector
private static Map<String, AttributeConfigElement> sortAttributes(
final Map<String, AttributeConfigElement> attributes, final XmlElement xml) {
final Map<String, AttributeConfigElement> sorted = Maps.newLinkedHashMap();
for (XmlElement xmlElement : xml.getChildElements()) {
final String name = xmlElement.getName();
if (!CONTEXT_INSTANCE.equals(name)) { // skip context
// instance child node
// because it
// specifies
// ObjectName
final AttributeConfigElement value = attributes.get(name);
if (value == null) {
throw new IllegalArgumentException("Cannot find yang mapping for node " + xmlElement);
}
sorted.put(name, value);
}
}
return sorted;
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public static boolean isErrorMessage(XmlElement xmlElement) throws NetconfDocumentedException {
if(xmlElement.getChildElements().size() != 1) {
return false;
}
return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.RPC_ERROR);
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public static boolean isOKMessage(XmlElement xmlElement) throws NetconfDocumentedException {
if(xmlElement.getChildElements().size() != 1) {
return false;
}
return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.OK);
}
代码示例来源:origin: org.opendaylight.controller/netconf-util
public XmlElement getOnlyChildElement(String childName) throws NetconfDocumentedException {
List<XmlElement> nameElements = getChildElements(childName);
if (nameElements.size() != 1){
throw new NetconfDocumentedException("One element " + childName + " expected in " + toString(),
NetconfDocumentedException.ErrorType.application,
NetconfDocumentedException.ErrorTag.invalid_value,
NetconfDocumentedException.ErrorSeverity.error);
}
return nameElements.get(0);
}
代码示例来源:origin: org.opendaylight.controller/netconf-testtool
private boolean containsDelete(final XmlElement element) {
for (final Attr o : element.getAttributes().values()) {
if (o.getLocalName().equals(OPERATION)
&& (o.getValue().equals(DELETE_EDIT_CONFIG) || o.getValue()
.equals(REMOVE_EDIT_CONFIG))) {
return true;
}
}
for (final XmlElement xmlElement : element.getChildElements()) {
if (containsDelete(xmlElement)) {
return true;
}
}
return false;
}
}
代码示例来源: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/config-netconf-connector
public Map<String, AttributeConfigElement> fromXml(XmlElement configRootNode) throws NetconfDocumentedException {
Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
// FIXME add identity map to runtime data
Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig,
Collections.<String, Map<Date, EditConfig.IdentityMapping>> emptyMap());
for (Entry<String, AttributeReadingStrategy> readStratEntry : strats.entrySet()) {
List<XmlElement> configNodes = configRootNode.getChildElements(readStratEntry.getKey());
AttributeConfigElement readElement = readStratEntry.getValue().readElement(configNodes);
retVal.put(readStratEntry.getKey(), readElement);
}
resolveConfiguration(retVal);
return retVal;
}
代码示例来源:origin: org.opendaylight.controller/sal-netconf-connector
private static Map.Entry<Date, XmlElement> stripNotification(final NetconfMessage message) {
final XmlElement xmlElement = XmlElement.fromDomDocument(message.getDocument());
final List<XmlElement> childElements = xmlElement.getChildElements();
Preconditions.checkArgument(childElements.size() == 2, "Unable to parse notification %s, unexpected format", message);
final XmlElement eventTimeElement;
final XmlElement notificationElement;
if (childElements.get(0).getName().equals(EVENT_TIME)) {
eventTimeElement = childElements.get(0);
notificationElement = childElements.get(1);
}
else if(childElements.get(1).getName().equals(EVENT_TIME)) {
eventTimeElement = childElements.get(1);
notificationElement = childElements.get(0);
} else {
throw new IllegalArgumentException("Notification payload does not contain " + EVENT_TIME + " " + message);
}
try {
return new AbstractMap.SimpleEntry<>(EVENT_TIME_FORMAT.get().parse(eventTimeElement.getTextContent()), notificationElement);
} catch (NetconfDocumentedException e) {
throw new IllegalArgumentException("Notification payload does not contain " + EVENT_TIME + " " + message);
} catch (ParseException e) {
LOG.warn("Unable to parse event time from {}. Setting time to {}", eventTimeElement, NetconfNotification.UNKNOWN_EVENT_TIME, e);
return new AbstractMap.SimpleEntry<>(NetconfNotification.UNKNOWN_EVENT_TIME, notificationElement);
}
}
代码示例来源: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
if (matches != MatchingResult.NO_MATCH && matches != MatchingResult.CONTENT_MISMATCH) {
boolean filterHasChildren = filter.getChildElements().isEmpty() == false;
for (XmlElement srcChild : src.getChildElements()) {
for (XmlElement filterChild : filter.getChildElements()) {
MatchingResult childMatch = addSubtree2(filterChild, srcChild, XmlElement.fromDomElement(copied));
if (childMatch == MatchingResult.CONTENT_MISMATCH) {
if (numberOfTextMatchingChildren == filter.getChildElements().size()) {
代码示例来源:origin: org.opendaylight.controller/config-netconf-connector
public static Services fromXml(XmlElement xml) throws NetconfDocumentedException {
Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
List<XmlElement> services = xml.getChildElements(SERVICE_KEY);
xml.checkUnrecognisedElements(services);
List<XmlElement> instances = service.getChildElements(XmlNetconfConstants.INSTANCE_KEY);
service.checkUnrecognisedElements(instances, typeElement);
代码示例来源:origin: org.opendaylight.controller/mdsal-netconf-connector
@VisibleForTesting
protected YangInstanceIdentifier getInstanceIdentifierFromFilter(XmlElement filterElement) throws NetconfDocumentedException {
if (filterElement.getChildElements().size() != 1) {
throw new NetconfDocumentedException("Multiple filter roots not supported yet",
ErrorType.application, ErrorTag.operation_not_supported, ErrorSeverity.error);
}
XmlElement element = filterElement.getOnlyChildElement();
DataSchemaNode schemaNode = getSchemaNodeFromNamespace(element);
return getReadPointFromNode(YangInstanceIdentifier.builder().build(), filterToNormalizedNode(element, schemaNode));
}
代码示例来源:origin: org.opendaylight.controller/config-netconf-connector
private Element toXml(Document doc, Object result, AttributeIfc returnType, String namespace, String elementName) throws NetconfDocumentedException {
AttributeMappingStrategy<?, ? extends OpenType<?>> mappingStrategy = new ObjectMapper().prepareStrategy(returnType);
Optional<?> mappedAttributeOpt = mappingStrategy.mapAttribute(result);
Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, returnType.getOpenType());
// FIXME: multiple return values defined as leaf-list and list in yang should not be wrapped in output xml element,
// they need to be appended directly under rpc-reply element
//
// Either allow List of Elements to be returned from NetconfOperation or
// pass reference to parent output xml element for netconf operations to
// append result(s) on their own
Element tempParent = XmlUtil.createElement(doc, "output", Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
new ObjectXmlWriter().prepareWritingStrategy(elementName, returnType, doc).writeElement(tempParent, namespace, mappedAttributeOpt.get());
XmlElement xmlElement = XmlElement.fromDomElement(tempParent);
return xmlElement.getChildElements().size() > 1 ? tempParent : xmlElement.getOnlyChildElement().getDomElement();
}
代码示例来源:origin: org.opendaylight.controller/netconf-testtool
@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException {
final XmlElement configElementData = operationElement.getOnlyChildElement(XmlNetconfConstants.CONFIG_KEY);
containsDelete(configElementData);
if(containsDelete(configElementData)){
storage.resetConfigList();
} else {
storage.setConfigList(configElementData.getChildElements());
}
return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
代码示例来源:origin: org.opendaylight.controller/mdsal-netconf-connector
@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException {
final Datastore targetDatastore = extractTargetParameter(operationElement);
if (targetDatastore == Datastore.running) {
throw new NetconfDocumentedException("edit-config on running datastore is not supported",
ErrorType.protocol,
ErrorTag.operation_not_supported,
ErrorSeverity.error);
}
final ModifyAction defaultAction = getDefaultOperation(operationElement);
final XmlElement configElement = getElement(operationElement, CONFIG_KEY);
for (XmlElement element : configElement.getChildElements()) {
final String ns = element.getNamespace();
final DataSchemaNode schemaNode = getSchemaNodeFromNamespace(ns, element).get();
final DataTreeChangeTracker changeTracker = new DataTreeChangeTracker(defaultAction);
final DomToNormalizedNodeParserFactory.BuildingStrategyProvider editOperationStrategyProvider = new EditOperationStrategyProvider(changeTracker);
parseIntoNormalizedNode(schemaNode, element, editOperationStrategyProvider);
executeOperations(changeTracker);
}
return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
内容来源于网络,如有侵权,请联系作者删除!