/** * Find "proper" qname of unknown node in case it comes from a grouping */ private static QName findQNameFromGrouping(final DataNodeContainer subtree, final SchemaContext ctx, final UnknownSchemaNode unknownSchemaNode, final String localIdentityName) { QName identityQName = null; for (UsesNode usesNode : subtree.getUses()) { SchemaNode dataChildByName = SchemaContextUtil.findDataSchemaNode(ctx, usesNode.getGroupingPath()); Module m = SchemaContextUtil.findParentModule(ctx, dataChildByName); List<UnknownSchemaNode> unknownSchemaNodes = dataChildByName.getUnknownSchemaNodes(); if(Collections2.transform(unknownSchemaNodes, UNKNOWN_NODE_TO_STRING).contains(UNKNOWN_NODE_TO_STRING.apply(unknownSchemaNode))) { identityQName = QName.create(dataChildByName.getQName(), localIdentityName); } } return identityQName; }
private String leafrefToDef(final LeafSchemaNode parentNode, final LeafrefTypeDefinition leafrefType, final String defaultValue) { Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!"); Preconditions.checkArgument(leafrefType.getPathStatement() != null, "The Path Statement for Leafref Type Definition cannot be NULL!"); final RevisionAwareXPath xpath = leafrefType.getPathStatement(); final String strXPath = xpath.toString(); if (strXPath != null) { if (strXPath.indexOf('[') == -1) { final Module module = findParentModule(schemaContext, parentNode); if (module != null) { final SchemaNode dataNode; if (xpath.isAbsolute()) { dataNode = findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath); } String result = getTypeDefaultConstruction((LeafSchemaNode) dataNode, defaultValue); return result; } } else { return "new java.lang.Object()"; } } return null; }
private String leafrefToDef(final LeafSchemaNode parentNode, final LeafrefTypeDefinition leafrefType, final String defaultValue) { Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!"); Preconditions.checkArgument(leafrefType.getPathStatement() != null, "The Path Statement for Leafref Type Definition cannot be NULL!"); final RevisionAwareXPath xpath = leafrefType.getPathStatement(); final String strXPath = xpath.toString(); if (strXPath != null) { if (strXPath.indexOf('[') == -1) { final Module module = findParentModule(schemaContext, parentNode); if (module != null) { final SchemaNode dataNode; if (xpath.isAbsolute()) { dataNode = findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath); } final String result = getTypeDefaultConstruction((LeafSchemaNode) dataNode, defaultValue); return result; } } else { return "new java.lang.Object()"; } } return null; }
@Override public Collection<NormalizedNodeUpdate> normalizedUpdates(@Nonnull final YangInstanceIdentifier topLevelIdentifier, @Nonnull final Map.Entry<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> entry) { final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) SchemaContextUtil .findDataSchemaNode(ctx, getSchemaPath(topLevelIdentifier, entry)); if (containerSchemaNode.isPresenceContainer()) { LOG.debug("Processing {} as presence container", topLevelIdentifier); // if presence container - create delete right away return ((ContainerNode) entry.getValue()).getValue().stream() .map(containerNode -> new NormalizedNodeUpdate( YangInstanceIdentifier.builder(topLevelIdentifier) .node(containerNode.getIdentifier()).build(), containerNode, null)) .collect(Collectors.toList()); } else { LOG.debug("Processing {} as non-presence container", topLevelIdentifier); // if non-presence - goes deep with base logic return super.normalizedUpdates(topLevelIdentifier, entry); } }
dataNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, unionType, xpath);
/** * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qname}. This handle * the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other * module as typedef which is then imported to referenced module. * * <p> * Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful. */ public static TypeDefinition<?> getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition, final SchemaContext schemaContext, final QName qname) { final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement(); final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl( stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute()); if (!strippedPathStatement.isAbsolute()) { return null; } final Optional<Module> parentModule = schemaContext.findModule(qname.getModule()); checkArgument(parentModule.isPresent(), "Failed to find parent module for %s", qname); final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule.get(), strippedPathStatement); final TypeDefinition<?> targetTypeDefinition = typeDefinition(dataSchemaNode); if (targetTypeDefinition instanceof LeafrefTypeDefinition) { return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode); } return targetTypeDefinition; }
dataNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, unionType, xpath);
/** * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qname}. This handle * the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other * module as typedef which is then imported to referenced module. * * <p> * Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful. */ public static TypeDefinition<?> getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition, final SchemaContext schemaContext, final QName qname) { final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement(); final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl( stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute()); if (!strippedPathStatement.isAbsolute()) { return null; } final Optional<Module> parentModule = schemaContext.findModule(qname.getModule()); checkArgument(parentModule.isPresent(), "Failed to find parent module for %s", qname); final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule.get(), strippedPathStatement); final TypeDefinition<?> targetTypeDefinition = typeDefinition(dataSchemaNode); if (targetTypeDefinition instanceof LeafrefTypeDefinition) { return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode); } return targetTypeDefinition; }
parentNode, leafRefStrippedXPath); } else { leafRefValueNode = SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule, leafRefStrippedXPath);
SchemaNode targetSchemaNode = null; targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); if (targetSchemaNode instanceof DataSchemaNode && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) { if (targetSchemaNode instanceof DerivableSchemaNode) {
final SchemaNode dataNode; if (xpath.isAbsolute()) { dataNode = findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
SchemaNode targetSchemaNode = null; targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); if (targetSchemaNode instanceof DataSchemaNode && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) { if (targetSchemaNode instanceof DerivableSchemaNode) {
dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule, pathStatement); } else {
SchemaNode parent = findDataSchemaNode(schemaContext, choiceNodeParentPath); SchemaNode targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); if (targetSchemaNode instanceof DataSchemaNode && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) {
dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule, pathStatement); } else {
parentSchema = path.getSchemaContext(); } else { parentSchema = SchemaContextUtil.findDataSchemaNode(path.getSchemaContext(), path.getSchemaNode().getPath().getParent());
dataNode = findDataSchemaNode(schemaContext, module, xpath); } else { dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
SchemaNode parent = findDataSchemaNode(schemaContext, choiceNodeParentPath); SchemaNode targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); if (targetSchemaNode instanceof DataSchemaNode && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) {
parent = findDataSchemaNode(schemaContext, nodeSp.getParent());
private GeneratedTypeBuilder findChildOfType(final ChoiceSchemaNode targetNode) { final SchemaPath nodePath = targetNode.getPath(); final SchemaPath parentSp = nodePath.getParent(); if (parentSp.getParent() == null) { return moduleContext(nodePath.getLastComponent().getModule()).getModuleNode(); } final SchemaNode parent = findDataSchemaNode(schemaContext, parentSp); GeneratedTypeBuilder childOfType = null; if (parent instanceof CaseSchemaNode) { childOfType = findCaseByPath(parent.getPath()); } else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) { childOfType = findChildNodeByPath(parent.getPath()); } else if (parent instanceof GroupingDefinition) { childOfType = findGroupingByPath(parent.getPath()); } if (childOfType == null) { throw new IllegalArgumentException("Failed to find parent type of choice " + targetNode); } return childOfType; }