gpt4 book ai didi

org.opendaylight.controller.netconf.util.xml.XmlElement类的使用及代码示例

转载 作者:知者 更新时间:2024-03-27 12:59:05 27 4
gpt4 key购买 nike

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

XmlElement介绍

暂无

代码示例

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

private static Document filtered(XmlElement filter, Document originalReplyDocument) throws NetconfDocumentedException {
  Document result = XmlUtil.newDocument();
  // even if filter is empty, copy /rpc/data
  Element rpcReply = originalReplyDocument.getDocumentElement();
  Node rpcReplyDst = result.importNode(rpcReply, false);
  result.appendChild(rpcReplyDst);
  XmlElement dataSrc = XmlElement.fromDomElement(rpcReply).getOnlyChildElement("data", XmlNetconfConstants.RFC4741_TARGET_NAMESPACE);
  Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false);
  rpcReplyDst.appendChild(dataDst);
  addSubtree(filter, dataSrc, XmlElement.fromDomElement(dataDst));
  return result;
}

代码示例来源: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/config-netconf-connector

private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) throws NetconfDocumentedException{
  XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
  Map.Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
  String serviceName = checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
  XmlElement nameElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
  String dependencyName = nameElement.getTextContent();
  return new ObjectNameAttributeMappingStrategy.MappedDependency(prefixNamespace.getValue(), serviceName,
      dependencyName);
}

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

public XmlElement getOnlyChildElementWithSameNamespace() throws NetconfDocumentedException {
  XmlElement childElement = getOnlyChildElement();
  childElement.checkNamespace(getNamespace());
  return childElement;
}

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

private static void checkXml(XmlElement xml) throws UnexpectedElementException, UnexpectedNamespaceException, MissingNameSpaceException {
  xml.checkName(XmlNetconfConstants.GET);
  xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
  // Filter option: ignore for now, TODO only load modules specified by the filter
}

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

public static XmlElement fromDomElementWithExpected(Element element, String expectedName) throws NetconfDocumentedException {
  XmlElement xmlElement = XmlElement.fromDomElement(element);
  xmlElement.checkName(expectedName);
  return xmlElement;
}

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

requestElement = getRequestElementWithCheck(message);
XmlElement operationElement = requestElement.getOnlyChildElement();
final String netconfOperationName = operationElement.getName();
final String netconfOperationNamespace;
try {
  netconfOperationNamespace = operationElement.getNamespace();
} catch (MissingNameSpaceException e) {
  LOG.debug("Cannot retrieve netconf operation namespace from message due to ", e);
    .getOnlyChildElementOptionally(CONTEXT_INSTANCE);
    .getTextContent(), netconfOperationName, netconfOperationNamespace);

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

private Datastore extractTargetParameter(final XmlElement operationElement) throws NetconfDocumentedException {
  final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(TARGET_KEY);
  // Direct lookup instead of using XmlElement class due to performance
  if (elementsByTagName.getLength() == 0) {
    throw new NetconfDocumentedException("Missing target element", ErrorType.rpc, ErrorTag.missing_attribute, ErrorSeverity.error);
  } else if (elementsByTagName.getLength() > 1) {
    throw new NetconfDocumentedException("Multiple target elements", ErrorType.rpc, ErrorTag.unknown_attribute, ErrorSeverity.error);
  } else {
    final XmlElement targetChildNode = XmlElement.fromDomElement((Element) elementsByTagName.item(0)).getOnlyChildElement();
    return Datastore.valueOf(targetChildNode.getName());
  }
}

代码示例来源: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/config-netconf-connector

xml.checkName(EditConfigXmlParser.EDIT_CONFIG);
xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
XmlElement targetChildNode = null;
try {
  targetElement  = xml.getOnlyChildElementWithSameNamespace(EditConfigXmlParser.TARGET_KEY);
  targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
} catch (final MissingNameSpaceException | UnexpectedNamespaceException e) {
  LOG.trace("Can't get only child element with same namespace", e);
  throw NetconfDocumentedException.wrap(e);
String datastoreValue = targetChildNode.getName();
Datastore targetDatastore = Datastore.valueOf(datastoreValue);
LOG.debug("Setting {} to '{}'", EditConfigXmlParser.TARGET_KEY, targetDatastore);
    .getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.TEST_OPTION_KEY);
if (testOptionElementOpt.isPresent()) {
  String testOptionValue = testOptionElementOpt.get().getTextContent();
  testOption = EditConfigXmlParser.TestOption.getFromXmlName(testOptionValue);
} else {
    .getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.ERROR_OPTION_KEY);
if (errorOptionElement.isPresent()) {
  String errorOptionParsed = errorOptionElement.get().getTextContent();
  if (!errorOptionParsed.equals(EditConfigXmlParser.DEFAULT_ERROR_OPTION)){
    throw new UnsupportedOperationException("Only " + EditConfigXmlParser.DEFAULT_ERROR_OPTION
    .getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.DEFAULT_OPERATION_KEY);
if (defaultContent.isPresent()) {

代码示例来源: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);
    XmlElement typeElement = service.getOnlyChildElement(TYPE_KEY);
    Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
    List<XmlElement> instances = service.getChildElements(XmlNetconfConstants.INSTANCE_KEY);
    service.checkUnrecognisedElements(instances, typeElement);
      XmlElement nameElement = instance.getOnlyChildElement(NAME_KEY);
      String refName = nameElement.getTextContent();
          instance.getAttribute(
              XmlNetconfConstants.OPERATION_ATTR_KEY,
              XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)))
        XmlElement providerElement = instance.getOnlyChildElement(PROVIDER_KEY);
        String providerName = providerElement.getTextContent();
        instance.checkUnrecognisedElements(nameElement, providerElement);

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

public static Datastore fromXml(XmlElement xml) throws UnexpectedNamespaceException, UnexpectedElementException, MissingNameSpaceException, NetconfDocumentedException {
  xml.checkName(GET_CONFIG);
  xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
  XmlElement sourceElement = xml.getOnlyChildElement(XmlNetconfConstants.SOURCE_KEY,
      XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
  XmlElement sourceNode = sourceElement.getOnlyChildElement();
  String sourceParsed = sourceNode.getName();
  LOG.debug("Setting source datastore to '{}'", sourceParsed);
  Datastore sourceDatastore = Datastore.valueOf(sourceParsed);
  // Filter option: ignore for now, TODO only load modules specified by the filter
  return sourceDatastore;
}

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

List<XmlElement> recognisedChildren = Lists.newArrayList();
XmlElement typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
XmlElement nameElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
List<XmlElement> typeAndNameElements = Lists.newArrayList(typeElement, nameElement);
  int size = moduleElement.getChildElements().size();
  int expectedChildNodes = 1 + typeAndNameElements.size();
  if (size > expectedChildNodes) {
    throw new NetconfDocumentedException("Error reading module " + typeElement.getTextContent() + " : " +
        nameElement.getTextContent() + " - Expected " + expectedChildNodes +" child nodes, " +
        "one of them with name " + nullableDummyContainerName +
        ", got " + size + " elements.");
      moduleElement = moduleElement.getOnlyChildElement(nullableDummyContainerName, moduleNamespace);
    } catch (NetconfDocumentedException e) {
      throw new NetconfDocumentedException("Error reading module " + typeElement.getTextContent() + " : " +
          nameElement.getTextContent() + " - Expected child node with name " + nullableDummyContainerName +
          "." + e.getMessage());
  moduleElement.checkUnrecognisedElements(recognisedChildren);
} catch (NetconfDocumentedException e) {
  throw new NetconfDocumentedException("Error reading module " + typeElement.getTextContent() + " : " +
      nameElement.getTextContent() + " - " +
      e.getMessage(), e.getErrorType(), e.getErrorTag(),e.getErrorSeverity(),e.getErrorInfo());
String perInstanceEditStrategy = moduleElement.getAttribute(XmlNetconfConstants.OPERATION_ATTR_KEY,
    XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);

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

private static MatchingResult addSubtree2(XmlElement filter, XmlElement src, XmlElement dstParent) throws NetconfDocumentedException {
  Document document = dstParent.getDomElement().getOwnerDocument();
  MatchingResult matches = matches(src, filter);
  if (matches != MatchingResult.NO_MATCH && matches != MatchingResult.CONTENT_MISMATCH) {
    boolean filterHasChildren = filter.getChildElements().isEmpty() == false;
    Element copied = (Element) document.importNode(src.getDomElement(), filterHasChildren == false);
    boolean shouldAppend = filterHasChildren == false;
    if (filterHasChildren) { // this implies TAG_MATCH
      for (XmlElement srcChild : src.getChildElements()) {
        for (XmlElement filterChild : filter.getChildElements()) {
          MatchingResult childMatch = addSubtree2(filterChild, srcChild, XmlElement.fromDomElement(copied));
          if (childMatch == MatchingResult.CONTENT_MISMATCH) {
            return MatchingResult.NO_MATCH;
      if (numberOfTextMatchingChildren == filter.getChildElements().size()) {
        copied = (Element) document.importNode(src.getDomElement(), true);
      dstParent.getDomElement().appendChild(copied);

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

@Override
public Document handle(final Document requestMessage,
            final NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
  final XmlElement requestElement = getRequestElementWithCheck(requestMessage);
  final Document document = XmlUtil.newDocument();
  final XmlElement operationElement = requestElement.getOnlyChildElement();
  final Map<String, Attr> attributes = requestElement.getAttributes();
  final Element response = handle(document, operationElement, subsequentOperation);
  final Element rpcReply = XmlUtil.createElement(document, XmlNetconfConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
  if(XmlElement.fromDomElement(response).hasNamespace()) {
    rpcReply.appendChild(response);
  } else {
    final NodeList list = response.getChildNodes();
    if (list.getLength() == 0) {
      rpcReply.appendChild(response);
    } else {
      while (list.getLength() != 0) {
        rpcReply.appendChild(list.item(0));
      }
    }
  }
  for (Attr attribute : attributes.values()) {
    rpcReply.setAttributeNode((Attr) document.importNode(attribute, true));
  }
  document.appendChild(rpcReply);
  return document;
}

代码示例来源:origin: org.opendaylight.controller/netconf-notifications-impl

private static Element getPlaceholder(final Document innerResult)
    throws NetconfDocumentedException {
  final XmlElement rootElement = XmlElement.fromDomElementWithExpected(
      innerResult.getDocumentElement(), XmlNetconfConstants.RPC_REPLY_KEY, XmlNetconfConstants.RFC4741_TARGET_NAMESPACE);
  return rootElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY).getDomElement();
}

代码示例来源: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-util

private static boolean isHelloMessage(final Document document) {
    XmlElement element = XmlElement.fromDomElement(document.getDocumentElement());
    try {
      // accept even if hello has no namespace
      return element.getName().equals(HELLO_TAG) &&
          (!element.hasNamespace() || element.getNamespace().equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
    } catch (MissingNameSpaceException e) {
      // Cannot happen, since we check for hasNamespace
      throw new IllegalStateException(e);
    }
  }
}

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

public OperationNameAndNamespace(final Document message) throws NetconfDocumentedException {
  XmlElement requestElement = null;
  requestElement = getRequestElementWithCheck(message);
  operationElement = requestElement.getOnlyChildElement();
  operationName = operationElement.getName();
  namespace = operationElement.getNamespace();
}

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