gpt4 book ai didi

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

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

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

XmlElement.getNamespace介绍

暂无

代码示例

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

public void checkNamespace(String expectedNamespace) throws UnexpectedNamespaceException, MissingNameSpaceException {
  if (!getNamespace().equals(expectedNamespace))
  {
    throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s",
        getNamespace(),
        expectedNamespace),
        NetconfDocumentedException.ErrorType.application,
        NetconfDocumentedException.ErrorTag.operation_failed,
        NetconfDocumentedException.ErrorSeverity.error);
  }
}

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

@Override
public boolean accept(Element e) {
  try {
    return XmlElement.fromDomElement(e).getNamespace().equals(namespace);
  } catch (MissingNameSpaceException e1) {
    return false;
  }
}

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

public List<XmlElement> getChildElementsWithSameNamespace(final String childName) throws MissingNameSpaceException {
  List<XmlElement> children = getChildElementsWithinNamespace(getNamespace());
  return Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
    @Override
    public boolean apply(XmlElement xmlElement) {
      return xmlElement.getName().equals(childName);
    }
  }));
}

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

@Override
public String toString() {
  final StringBuilder sb = new StringBuilder("XmlElement{");
  sb.append("name='").append(getName()).append('\'');
  if (element.getNamespaceURI() != null) {
    try {
      sb.append(", namespace='").append(getNamespace()).append('\'');
    } catch (MissingNameSpaceException e) {
      LOG.trace("Missing namespace for element.");
    }
  }
  sb.append('}');
  return sb.toString();
}

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

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

代码示例来源: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 XmlElement getOnlyChildElementWithSameNamespace() throws NetconfDocumentedException {
  XmlElement childElement = getOnlyChildElement();
  childElement.checkNamespace(getNamespace());
  return childElement;
}

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

@Override
protected String readElementContent(XmlElement xmlElement) throws NetconfDocumentedException {
  Map.Entry<String, String> namespaceOfTextContent = xmlElement.findNamespaceOfTextContent();
  String content = xmlElement.getTextContent();
  final String namespace;
  final String localName;
  if(namespaceOfTextContent.getKey().isEmpty()) {
    localName = content;
    namespace = xmlElement.getNamespace();
  } else {
    String prefix = namespaceOfTextContent.getKey() + ":";
    Preconditions.checkArgument(content.startsWith(prefix), "Identity ref should be prefixed with \"%s\"", prefix);
    localName = content.substring(prefix.length());
    namespace = namespaceOfTextContent.getValue();
  }
  Date revision = null;
  Map<Date, EditConfig.IdentityMapping> revisions = identityMap.get(namespace);
  if(revisions.keySet().size() > 1) {
    for (Map.Entry<Date, EditConfig.IdentityMapping> revisionToIdentityEntry : revisions.entrySet()) {
      if(revisionToIdentityEntry.getValue().containsIdName(localName)) {
        Preconditions.checkState(revision == null, "Duplicate identity %s, in namespace %s, with revisions: %s, %s detected. Cannot map attribute",
            localName, namespace, revision, revisionToIdentityEntry.getKey());
        revision = revisionToIdentityEntry.getKey();
      }
    }
  } else {
    revision = revisions.keySet().iterator().next();
  }
  return QName.create(URI.create(namespace), revision, localName).toString();
}

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

private DataSchemaNode getSchemaNodeFromNamespace(final XmlElement element) throws NetconfDocumentedException {
  try {
    final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(new URI(element.getNamespace()), null);
    DataSchemaNode dataSchemaNode = module.getDataChildByName(element.getName());
    if (dataSchemaNode != null) {
      return dataSchemaNode;
    }
  } catch (URISyntaxException e) {
    LOG.debug("Error during parsing of element namespace, this should not happen since namespace of an xml " +
        "element is valid and if the xml was parsed then the URI should be as well");
    throw new IllegalArgumentException("Unable to parse element namespace, this should not happen since " +
        "namespace of an xml element is valid and if the xml was parsed then the URI should be as well");
  }
  throw new NetconfDocumentedException("Unable to find node with namespace: " + element.getNamespace() + "in schema context: " + schemaContext.getCurrentContext().toString(),
      ErrorType.application,
      ErrorTag.unknown_namespace,
      ErrorSeverity.error);
}

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

@Override
public synchronized DOMNotification toNotification(final NetconfMessage message) {
  final Map.Entry<Date, XmlElement> stripped = stripNotification(message);
  final QName notificationNoRev;
  try {
    notificationNoRev = QName.create(stripped.getValue().getNamespace(), stripped.getValue().getName()).withoutRevision();
  } catch (final MissingNameSpaceException e) {
    throw new IllegalArgumentException("Unable to parse notification " + message + ", cannot find namespace", e);
  }
  final Collection<NotificationDefinition> notificationDefinitions = mappedNotifications.get(notificationNoRev);
  Preconditions.checkArgument(notificationDefinitions.size() > 0,
      "Unable to parse notification %s, unknown notification. Available notifications: %s", notificationDefinitions, mappedNotifications.keySet());
  // FIXME if multiple revisions for same notifications are present, we should pick the most recent. Or ?
  // We should probably just put the most recent notification versions into our map. We can expect that the device sends the data according to the latest available revision of a model.
  final NotificationDefinition next = notificationDefinitions.iterator().next();
  // We wrap the notification as a container node in order to reuse the parsers and builders for container node
  final ContainerSchemaNode notificationAsContainerSchemaNode = NetconfMessageTransformUtil.createSchemaForNotification(next);
  final ContainerNode content = parserFactory.getContainerNodeParser().parse(Collections.singleton(stripped.getValue().getDomElement()),
      notificationAsContainerSchemaNode);
  return new NetconfDeviceNotification(content, stripped.getKey());
}

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

final String netconfOperationNamespace;
try {
  netconfOperationNamespace = operationElement.getNamespace();
} catch (MissingNameSpaceException e) {
  LOG.debug("Cannot retrieve netconf operation namespace from message due to ", e);

代码示例来源: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());
}

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

final String netconfOperationNamespace;
try {
  netconfOperationNamespace = operationElement.getNamespace();
} catch (MissingNameSpaceException e) {
  LOG.debug("Cannot retrieve netconf operation namespace from message due to ", e);

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

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