gpt4 book ai didi

org.opendaylight.controller.config.util.xml.XmlElement.getChildElements()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-21 02:21:05 25 4
gpt4 key购买 nike

本文整理了Java中org.opendaylight.controller.config.util.xml.XmlElement.getChildElements()方法的一些代码示例,展示了XmlElement.getChildElements()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlElement.getChildElements()方法的具体详情如下:
包路径:org.opendaylight.controller.config.util.xml.XmlElement
类名称:XmlElement
方法名:getChildElements

XmlElement.getChildElements介绍

暂无

代码示例

代码示例来源:origin: org.opendaylight.netconf/netconf-util

private static void addSubtree(XmlElement filter, XmlElement src, XmlElement dst) throws DocumentedException {
  for (XmlElement srcChild : src.getChildElements()) {
    for (XmlElement filterChild : filter.getChildElements()) {
      addSubtree2(filterChild, srcChild, dst);
    }
  }
}

代码示例来源:origin: org.opendaylight.controller/config-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/config-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/config-util

public void checkUnrecognisedElements(List<XmlElement> recognisedElements,
                   XmlElement... additionalRecognisedElements) throws DocumentedException {
  List<XmlElement> childElements = getChildElements();
  childElements.removeAll(recognisedElements);
  for (XmlElement additionalRecognisedElement : additionalRecognisedElements) {
    childElements.remove(additionalRecognisedElement);
  }
  if (!childElements.isEmpty()){
    throw new DocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
        DocumentedException.ErrorType.application,
        DocumentedException.ErrorTag.invalid_value,
        DocumentedException.ErrorSeverity.error);
  }
}

代码示例来源:origin: org.opendaylight.controller/config-util

public XmlElement getOnlyChildElement() throws DocumentedException {
  List<XmlElement> children = getChildElements();
  if (children.size() != 1){
    throw new DocumentedException(String.format( "One element expected in %s but was %s", toString(),
        children.size()),
        DocumentedException.ErrorType.application,
        DocumentedException.ErrorTag.invalid_value,
        DocumentedException.ErrorSeverity.error);
  }
  return children.get(0);
}

代码示例来源:origin: org.opendaylight.controller/config-util

public XmlElement getOnlyChildElement(String childName) throws DocumentedException {
  List<XmlElement> nameElements = getChildElements(childName);
  if (nameElements.size() != 1){
    throw new DocumentedException("One element " + childName + " expected in " + toString(),
        DocumentedException.ErrorType.application,
        DocumentedException.ErrorTag.invalid_value,
        DocumentedException.ErrorSeverity.error);
  }
  return nameElements.get(0);
}

代码示例来源:origin: org.opendaylight.netconf/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 &lt;data/&gt; container in the response.
 *         if filter is not present we want to read the entire datastore - return ROOT.
 * @throws DocumentedException
 */
protected Optional<YangInstanceIdentifier> getDataRootFromFilter(XmlElement operationElement) throws DocumentedException {
  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.netconf/mdsal-netconf-connector

@VisibleForTesting
protected YangInstanceIdentifier getInstanceIdentifierFromFilter(XmlElement filterElement) throws DocumentedException {
  if (filterElement.getChildElements().size() != 1) {
    throw new DocumentedException("Multiple filter roots not supported yet",
        ErrorType.application, ErrorTag.operation_not_supported, ErrorSeverity.error);
  }
  XmlElement element = filterElement.getOnlyChildElement();
  return validator.validate(element);
}

代码示例来源:origin: org.opendaylight.netconf/netconf-util

public static boolean isOKMessage(XmlElement xmlElement) throws NetconfDocumentedException {
  if(xmlElement.getChildElements().size() != 1) {
    return false;
  }
  try {
    return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.OK);
  } catch (DocumentedException e) {
    throw new NetconfDocumentedException(e);
  }
}

代码示例来源:origin: org.opendaylight.netconf/netconf-util

public static boolean isErrorMessage(XmlElement xmlElement) throws NetconfDocumentedException {
  if(xmlElement.getChildElements().size() != 1) {
    return false;
  }
  try {
    return xmlElement.getOnlyChildElement().getName().equals(DocumentedException.RPC_ERROR);
  } catch (DocumentedException e) {
    throw new NetconfDocumentedException(e);
  }
}

代码示例来源:origin: org.opendaylight.netconf/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 (DocumentedException e) {
          LOG.trace("Error fetching input text content",e);
          return null;
        }
      }
    });

  }
}

代码示例来源:origin: org.opendaylight.netconf/netconf-util

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.netconf/netconf-util

private static Document filteredNotification(XmlElement filter, Document originalNotification) throws DocumentedException {
  Document result = XmlUtil.newDocument();
  XmlElement dataSrc = XmlElement.fromDomDocument(originalNotification);
  Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false);
  for (XmlElement filterChild : filter.getChildElements()) {
    addSubtree2(filterChild, dataSrc.getOnlyChildElement(), XmlElement.fromDomElement(dataDst));
  }
  if(dataDst.getFirstChild() != null) {
    result.appendChild(dataDst.getFirstChild());
    return result;
  } else {
    return null;
  }
}

代码示例来源:origin: org.opendaylight.netconf/mdsal-netconf-connector

/**
 * Recursively checks filter elements against the schema. Returns tree of nodes QNames as they appear in filter.
 * @param element element to check
 * @param parentNodeSchema parent node schema
 * @param tree parent node tree
 * @return tree
 * @throws ValidationException if filter content is not valid
 */
private FilterTree validateNode(XmlElement element, DataSchemaNode parentNodeSchema, FilterTree tree) throws ValidationException {
  final List<XmlElement> childElements = element.getChildElements();
  for (XmlElement childElement : childElements) {
    try {
      final Deque<DataSchemaNode> path = findSchemaNodeByNameAndNamespace(parentNodeSchema, childElement.getName(), new URI(childElement.getNamespace()));
      if (path.isEmpty()) {
        throw new ValidationException(element, childElement);
      }
      FilterTree subtree = tree;
      for (DataSchemaNode dataSchemaNode : path) {
          subtree = subtree.addChild(dataSchemaNode);
      }
      final DataSchemaNode childSchema = path.getLast();
      validateNode(childElement, childSchema, subtree);
    } catch (URISyntaxException | MissingNameSpaceException e) {
      throw new RuntimeException("Wrong namespace in element + " + childElement.toString());
    }
  }
  return tree;
}

代码示例来源:origin: org.opendaylight.netconf/mdsal-netconf-connector

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
  final Datastore targetDatastore = extractTargetParameter(operationElement);
  if (targetDatastore == Datastore.running) {
    throw new DocumentedException("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());
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com