gpt4 book ai didi

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

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

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

XmlElement.getOnlyChildElement介绍

暂无

代码示例

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

public XmlElement getOnlyChildElementWithSameNamespace(String childName) throws  NetconfDocumentedException {
  return getOnlyChildElement(childName, getNamespace());
}

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

requestElement = getRequestElementWithCheck(message);
XmlElement operationElement = requestElement.getOnlyChildElement();
final String netconfOperationName = operationElement.getName();
final String netconfOperationNamespace;

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

public static Document checkIsMessageOk(Document response) throws NetconfDocumentedException {
    XmlElement element = XmlElement.fromDomDocument(response);
    Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
    element = element.getOnlyChildElement();
    if (element.getName().equals(XmlNetconfConstants.OK)) {
      return response;
    }
    LOG.warn("Can not load last configuration. Operation failed.");
    throw new IllegalStateException("Can not load last configuration. Operation failed: "
        + XmlUtil.toString(response));
  }
}

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

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

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

private Element getConfigSnapshot(final NetconfOperationRouter opRouter) throws NetconfDocumentedException {
  final Document responseDocument = opRouter.onNetconfMessage(
      getConfigMessage, null);
  XmlElement dataElement;
  XmlElement xmlElement = XmlElement.fromDomElementWithExpected(responseDocument.getDocumentElement(),
      XmlNetconfConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
  dataElement = xmlElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY);
  return dataElement.getDomElement();
}

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

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

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

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

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

private void checkXml(XmlElement xml) throws NetconfDocumentedException {
  xml.checkName(VALIDATE);
  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 sourceChildNode = sourceElement.getOnlyChildElement();
  sourceChildNode.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
  String datastoreValue = sourceChildNode.getName();
  Datastore sourceDatastore = Datastore.valueOf(datastoreValue);
  if (sourceDatastore != Datastore.candidate){
    throw new NetconfDocumentedException( "Only " + Datastore.candidate
        + " is supported as source for " + VALIDATE + " but was " + datastoreValue,ErrorType.application,ErrorTag.data_missing,ErrorSeverity.error);
  }
}

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

@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/config-netconf-connector

public NetconfOperationExecution fromXml(final XmlElement xml) throws NetconfDocumentedException {
  final String namespace;
  try {
    namespace = xml.getNamespace();
  } catch (MissingNameSpaceException e) {
    LOG.trace("Can't get namespace from xml element due to ",e);
    throw NetconfDocumentedException.wrap(e);
  }
  final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE);
  final String operationName = xml.getName();
  final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath(
      contextInstanceElement.getTextContent(), operationName, namespace);
  final Rpcs rpcs = mapRpcs(yangStoreSnapshot.getModuleMXBeanEntryMap(), yangStoreSnapshot.getEnumResolver());
  final ModuleRpcs rpcMapping = rpcs.getRpcMapping(id);
  final InstanceRuntimeRpc instanceRuntimeRpc = rpcMapping.getRpc(id.getRuntimeBeanName(), operationName);
  // TODO move to Rpcs after xpath attribute is redesigned
  final ObjectName on = id.getObjectName(rpcMapping);
  Map<String, AttributeConfigElement> attributes = instanceRuntimeRpc.fromXml(xml);
  attributes = sortAttributes(attributes, xml);
  return new NetconfOperationExecution(on, instanceRuntimeRpc.getName(), attributes,
      instanceRuntimeRpc.getReturnType(), namespace);
}

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