gpt4 book ai didi

org.onosproject.yang.compiler.datamodel.YangNode.getParent()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 13:59:31 34 4
gpt4 key购买 nike

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

YangNode.getParent介绍

[英]Returns the parent of node.
[中]返回节点的父节点。

代码示例

代码示例来源:origin: org.onosproject/onos-yang-compiler-linker

/**
 * Returns the YANG node from uses augment.
 *
 * @param node  YANG node
 * @param count number of ancestors
 * @return YANG node.
 */
private static YangNode getNodeFromUsesAug(YangNode node, int count) {
  for (int val = 0; val < count; val++) {
    node = node.getParent();
  }
  return node;
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-linker

/**
 * Returns feature holder(module/sub-module node) .
 *
 * @param ancestorRefNode if-feature holder node
 */
private YangFeatureHolder getFeatureHolder(YangNode ancestorRefNode) {
  while (ancestorRefNode != null) {
    if (ancestorRefNode instanceof YangFeatureHolder) {
      return (YangFeatureHolder) ancestorRefNode;
    }
    ancestorRefNode = ancestorRefNode.getParent();
  }
  return null;
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Returns the contained data model parent node.
 *
 * @param curNode current node
 * @return parent node in which the current node is an attribute
 */
public static YangNode getParentNodeInGenCode(YangNode curNode) {
  /*
   * TODO: recursive parent lookup to support choice/augment/uses. TODO:
   * need to check if this needs to be updated for
   * choice/case/augment/grouping
   */
  YangNode parent = curNode.getParent();
  if (curNode instanceof YangAugment && parent instanceof YangUses) {
    parent = parent.getParent();
  }
  return parent;
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-linker

/**
   * Sets descendant node augmented flag in ancestors.
   *
   * @param targetNode augmented YANG node
   */
  private void setAugmentedFlagInAncestors(YangNode targetNode) {
    targetNode = targetNode.getParent();
    while (targetNode != null) {
      targetNode.setDescendantNodeAugmented(true);
      targetNode = targetNode.getParent();
    }
  }
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Returns true if op type info required for node.
 *
 * @return true if op type info required for node
 */
public boolean isOpTypeReq() {
  return this instanceof RpcNotificationContainer ||
      !(this instanceof InvalidOpTypeHolder) &&
          getParent().isOpTypeReq();
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

private boolean isListPresentInGrouping() {
  YangNode node = getParent();
  while (node != null) {
    if (node instanceof YangGrouping) {
      return true;
    }
    node = node.getParent();
  }
  return false;
  // TODO When grouping linking is done this method has to be modified.
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Processes addition of schema node child to parent map.
 *
 * @param name      name of the node
 * @param namespace namespace of the node
 */
protected void processAdditionOfSchemaNodeToParentMap(String name,
                           YangNamespace namespace) {
  processAdditionOfSchemaNodeToMap(name, namespace, this, getParent());
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-linker

/**
 * Returns module or sub-module node of any YANG node.
 *
 * @param node YANG node
 * @return root node
 */
private static YangNode getTgtRootNode(YangNode node) {
  YangNode root = node;
  while (!(root instanceof YangReferenceResolver)) {
    root = root.getParent();
    if (root == null) {
      throw new LinkerException("Datamodel tree is not correct");
    }
  }
  return root;
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-parser

/**
 * Returns the root node from the current node.
 *
 * @param node YANG node
 * @return root node
 */
private static YangNode getRootNode(YangNode node) {
  YangNode curNode = node;
  while (!(curNode instanceof YangModule) &&
      !(curNode instanceof YangSubModule)) {
    if (curNode == null) {
      throw new ParserException(INVALID_TREE);
    }
    curNode = curNode.getParent();
  }
  return curNode;
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-linker

/**
 * Skips the invalid nodes which cannot have data from YANG.
 *
 * @param curParent current parent
 * @param leafRef   YANG leaf-ref
 * @return parent node which can hold data
 * @throws LinkerException if linker rules are violated
 */
public static YangNode skipInvalidDataNodes(YangNode curParent,
                      YangLeafRef leafRef)
    throws LinkerException {
  YangNode node = curParent;
  while (node instanceof YangChoice ||
      node instanceof YangCase) {
    if (node.getParent() == null) {
      throw new LinkerException(getLeafRefErrorInfo(leafRef));
    }
    node = node.getParent();
  }
  return node;
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Returns the parent data node schema context for given yang node.
 *
 * @param node yang node
 * @return yang node
 */
public static YangNode getParentSchemaContext(YangNode node) {
  while (!(node instanceof SchemaDataNode) && node != null) {
    if (node.getYangSchemaNodeType() == YANG_AUGMENT_NODE) {
      node = ((YangAugment) node).getAugmentedNode();
      continue;
    }
    node = node.getParent();
  }
  return node;
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-parser

/**
 * Returns parent node config value, if top node does not specify a config
 * statement then default value true is returned.
 *
 * @param listener listener's object
 * @return true/false parent's config value
 */
public static boolean getParentNodeConfig(TreeWalkListener listener) {
  Parsable curData = listener.getParsedDataStack().peek();
  YangNode parentNode = ((YangNode) curData).getParent();
  if (curData instanceof YangConfig) {
    return ((YangConfig) curData).isConfig();
  } else if (curData instanceof YangRpc || curData instanceof YangOutput
      || curData instanceof YangInput || curData instanceof YangNotification) {
    return false;
  } else if (curData instanceof YangCase && parentNode instanceof YangChoice) {
    return ((YangChoice) parentNode).isConfig();
  } else {
    return true;
  }
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Adds namespace for self, next sibling and first child. This is used
 * after obtaining namespace in case of submodule after performing
 * linking.
 */
public void setNameSpaceAndAddToParentSchemaMap() {
  // Get parent namespace.
  if (getParent() != null && getParent().getNodeType() != ANYDATA_NODE) {
    // Get parent namespace and set namespace for self node.
    setNameSpace(getParent().getNameSpace());
    // Process addition of leaf to the child schema map of parent.
    processAdditionOfSchemaNodeToParentMap(getName(), getNameSpace());
  } else if (getParent() != null && getParent().getNodeType() == ANYDATA_NODE) {
    processAdditionOfSchemaNodeToParentMap(getName(), getNameSpace());
  } else {
    // Module/Sub-module
    setNameSpace((YangNamespace) this);
  }
  /*
   * Check if node contains leaf/leaf-list, if yes add namespace for leaf
   * and leaf list.
   */
  if (this instanceof YangLeavesHolder) {
    ((YangLeavesHolder) this).setLeafNameSpaceAndAddToParentSchemaMap();
  }
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Assigns leafref with new prefixes while cloning.
 *
 * @param importedNodeName imported node name from grouping
 * @param atomicPath       atomic path in leafref
 * @param node             instance of YANG uses where cloning is done
 * @throws DataModelException data model error
 */
private static void assignCurrentLeafedWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath,
                            YangNode node)
    throws DataModelException {
  while (!(node instanceof YangReferenceResolver)) {
    node = node.getParent();
    if (node == null) {
      throw new DataModelException("Internal datamodel error: Datamodel tree is not correct");
    }
  }
  if (node instanceof YangModule) {
    List<YangImport> importInUsesList = ((YangModule) node).getImportList();
    if (importInUsesList != null && !importInUsesList.isEmpty()) {
      Iterator<YangImport> importInUsesListIterator = importInUsesList.listIterator();
      while (importInUsesListIterator.hasNext()) {
        YangImport importInUsesNode = importInUsesListIterator.next();
        if (importInUsesNode.getModuleName().equals(importedNodeName)) {
          atomicPath.getNodeIdentifier().setPrefix(importInUsesNode.getPrefixId());
        }
      }
    }
  }
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

@Override
public void setNameSpaceAndAddToParentSchemaMap() {
  // Get parent namespace and set namespace for self node.
  YangNode parent = getParent();
  if (parent instanceof YangUses) {
    parent = parent.getParent();
  }
  setNameSpace(parent.getNameSpace());
  /*
   * Check if node contains leaf/leaf-list, if yes add namespace for leaf
   * and leaf list.
   */
  setLeafNameSpaceAndAddToParentSchemaMap();
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-linker

/**
 * Returns the augment node, that contains the node to be searched.
 *
 * @param temp parent YANG node
 * @param id   node id to be searched
 * @return YANG augment node
 */
private YangAugment getAugmentNode(YangNode temp, String id) {
  String augId = getAugNodeId(id);
  YangNode parent = temp.getParent();
  List<YangUses> usesList = getUsesNode(parent);
  for (YangUses uses : usesList) {
    List<YangAugment> augList = getAugList(uses);
    if (!augList.isEmpty()) {
      for (YangAugment aug : augList) {
        if (aug.getPrefixRemovedName().equals(augId)) {
          return aug;
        }
      }
    }
  }
  // TODO: Has to be more specific error message.
  throw new LinkerException("Invalid augment path");
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

@Override
  public YangSchemaNode addSchema(YangSchemaNode containedSchema) throws
      IllegalArgumentException {
    YangNode nodeToClone = (YangNode) containedSchema;
    try {
      cloneSubTree(nodeToClone.getParent(), this, null,
             false, nodeToClone);
    } catch (DataModelException e) {
      throw new IllegalArgumentException(e);
    }
    YangNode child = getChild();
    // Contained Schema Name
    String name = containedSchema.getName();
    while (child.getName() != name) {
      child = child.getNextSibling();
    }
    return child;
  }
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-linker

private static void traverseAndBreak(YangNode rootNode,
                   Map<YangNode, List<YangNode>> map) {
  YangNode curNode = rootNode;
  TraversalType curTraversal = ROOT;
  while (curNode != null) {
    if (curTraversal != PARENT && curNode.getChild() != null) {
      curTraversal = CHILD;
      curNode = curNode.getChild();
    } else if (curNode.getNextSibling() != null) {
      curTraversal = SIBLING;
      curNode = curNode.getNextSibling();
    } else {
      curTraversal = PARENT;
      curNode = curNode.getParent();
      if (curNode != null) {
        processHierarchyChild(curNode, map);
      }
    }
  }
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Sets parent context of data node.
 */
public void setParentContext() {
  if (this instanceof SchemaDataNode) {
    SchemaContext t = getParentSchemaContext(this.getParent());
    if (t != null) {
      parentContext = t;
    }
    // As rpc and anydata node is not leaf holder
    if (nodeType != RPC_NODE && nodeType != ANYDATA_NODE) {
      ((YangLeavesHolder) this).setLeafParentContext();
    }
    // setting the schema Id
    schemaId = new SchemaId(getName(), getNameSpace()
        .getModuleNamespace());
  } else if (this instanceof YangCase || this instanceof YangAugment) {
    ((YangLeavesHolder) this).setLeafParentContext();
  }
}

代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel

/**
 * Removes node from data model tree.
 *
 * @param node YANG data model node
 */
public static void deleteUnsupportedNodeFromTree(YangNode node) {
  // unlink from parent
  YangNode parentNode = node.getParent();
  if (parentNode.getChild().equals(node)) {
    parentNode.setChild(node.getNextSibling());
  }
  //unlink from siblings
  YangNode previousSibling = node.getPreviousSibling();
  YangNode nextSibling = node.getNextSibling();
  if (nextSibling != null && previousSibling != null) {
    previousSibling.setNextSibling(nextSibling);
    nextSibling.setPreviousSibling(previousSibling);
  } else if (nextSibling != null) {
    nextSibling.setPreviousSibling(null);
  } else if (previousSibling != null) {
    previousSibling.setNextSibling(null);
  }
  node.setParent(null);
  node.setPreviousSibling(null);
  node.setNextSibling(null);
  node.setChild(null);
}

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