org.opendaylight.yangtools.yang.model.api.SchemaNode Java Examples
The following examples show how to use
org.opendaylight.yangtools.yang.model.api.SchemaNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaContextUtil.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static Iterable<QName> resolveRelativePath(final SchemaContext context, final Module module, final SchemaNode actualSchemaNode, final List<String> steps) { // Find out how many "parent" components there are and trim them final int colCount = normalizeXPath(steps); final List<String> xpaths = colCount == 0 ? steps : steps.subList(colCount, steps.size()); final List<QName> walkablePath = createWalkablePath(actualSchemaNode.getPath().getPathFromRoot(), context, colCount); if (walkablePath.size() - colCount >= 0) { return Iterables.concat(Iterables.limit(walkablePath, walkablePath.size() - colCount), Iterables.transform(xpaths, input -> stringPathPartToQName(context, module, input))); } return Iterables.concat(walkablePath, Iterables.transform(xpaths, input -> stringPathPartToQName(context, module, input))); }
Example #2
Source File: ModuleStmtContext.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private ModuleStmtContext(final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> delegate, final Collection<StmtContext<?, ?, ?>> submodules) { this.delegate = requireNonNull(delegate); final List<StmtContext<?, ?, ?>> statements = new ArrayList<>(delegate.effectiveSubstatements()); final Set<Module> subs = new LinkedHashSet<>(submodules.size()); for (StmtContext<?, ?, ?> submoduleCtx : submodules) { final EffectiveStatement<?, ?> submodule = submoduleCtx.buildEffective(); verify(submodule instanceof Module, "Submodule statement %s is not a Module", submodule); subs.add((Module) submodule); for (StmtContext<?, ?, ?> stmt : submoduleCtx.allSubstatements()) { if (stmt.isSupportedByFeatures()) { final EffectiveStatement<?, ?> effective = stmt.buildEffective(); if (effective instanceof SchemaNode || effective instanceof DataNodeContainer) { statements.add(stmt); } } } } this.effectiveSubstatements = ImmutableList.copyOf(statements); this.submodules = ImmutableSet.copyOf(subs); }
Example #3
Source File: SchemaContextUtil.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext, final SchemaNode schemaNode) { checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!"); checkArgument(schemaNode instanceof TypedDataSchemaNode, "Unsupported node %s", schemaNode); TypeDefinition<?> nodeType = ((TypedDataSchemaNode) schemaNode).getType(); if (nodeType.getBaseType() != null) { while (nodeType.getBaseType() != null) { nodeType = nodeType.getBaseType(); } return schemaContext.findModule(nodeType.getQName().getModule()).orElse(null); } return findParentModule(schemaContext, schemaNode); }
Example #4
Source File: SchemaTracker.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private SchemaNode getSchema(final PathArgument name) { final Object parent = getParent(); SchemaNode schema = null; final QName qname = name.getNodeType(); if (parent instanceof DataNodeContainer) { schema = ((DataNodeContainer)parent).getDataChildByName(qname); if (schema == null) { if (parent instanceof GroupingDefinition) { schema = (GroupingDefinition) parent; } else if (parent instanceof NotificationDefinition) { schema = (NotificationDefinition) parent; } } } else if (parent instanceof ChoiceSchemaNode) { schema = findChildInCases((ChoiceSchemaNode) parent, qname); } else { throw new IllegalStateException("Unsupported schema type " + parent.getClass() + " on stack."); } checkArgument(schema != null, "Could not find schema for node %s in %s", qname, parent); return schema; }
Example #5
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void nodeTest() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources( "/semantic-statement-parser/multiple-revisions/node-test"); assertNotNull(context); QName root = QName.create("foo", "2016-04-06", "foo-root"); QName container20160404 = QName.create("foo", "2016-04-06", "con20160404"); SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160404)); assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); QName container20160405 = QName.create("foo", "2016-04-06", "con20160405"); findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160405)); assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); QName container20160406 = QName.create("foo", "2016-04-06", "con20160406"); findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160406)); assertNull(findDataSchemaNode); }
Example #6
Source File: YT1100Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testChoiceCaseRelativeLeafref() { final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt1100.yang"); final Module module = context.findModule("yt1100").orElseThrow(); final QNameModule qnm = module.getQNameModule(); final DataSchemaNode leaf = module.findDataTreeChild( QName.create(qnm, "foo"), QName.create(qnm, "scheduler-node"), QName.create(qnm, "child-scheduler-nodes"), QName.create(qnm, "name")).orElseThrow(); assertThat(leaf, instanceOf(LeafSchemaNode.class)); final TypeDefinition<?> type = ((LeafSchemaNode) leaf).getType(); assertThat(type, instanceOf(LeafrefTypeDefinition.class)); final PathExpression leafref = ((LeafrefTypeDefinition) type).getPathStatement(); final SchemaNode ref = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf, leafref); assertThat(ref, instanceOf(LeafSchemaNode.class)); final LeafSchemaNode targetLeaf = (LeafSchemaNode) ref; assertEquals(QName.create(qnm, "name"), targetLeaf.getQName()); assertThat(targetLeaf.getType(), instanceOf(StringTypeDefinition.class)); }
Example #7
Source File: SchemaUtils.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Finds schema node for given path in schema context. This method performs lookup in both the namespace * of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions, * notifications, anydatas and anyxmls according to Rfc6050/Rfc7950 section 6.2.1. * * <p> * This method returns collection of SchemaNodes, because name conflicts can occur between the namespace * of groupings and namespace of data nodes. This method finds and collects all schema nodes that matches supplied * SchemaPath and returns them all as collection of schema nodes. * * @param schemaContext * schema context * @param path * path * @return collection of schema nodes on path */ public static Collection<SchemaNode> findParentSchemaNodesOnPath(final SchemaContext schemaContext, final SchemaPath path) { final Collection<SchemaNode> currentNodes = new ArrayList<>(); final Collection<SchemaNode> childNodes = new ArrayList<>(); currentNodes.add(requireNonNull(schemaContext)); for (final QName qname : path.getPathFromRoot()) { for (final SchemaNode current : currentNodes) { childNodes.addAll(findChildSchemaNodesByQName(current, qname)); } currentNodes.clear(); currentNodes.addAll(childNodes); childNodes.clear(); } return currentNodes; }
Example #8
Source File: Bug8803Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { final SchemaPath topContPath = SchemaPath.create(true, QName.create("foo-ns", "top-cont")); final SchemaNode dataSchemaNode = SchemaContextUtil.findDataSchemaNode(SCHEMA_CONTEXT, topContPath); assertTrue(dataSchemaNode instanceof ContainerSchemaNode); final ContainerSchemaNode topContSchema = (ContainerSchemaNode) dataSchemaNode; final InputStream resourceAsStream = Bug8803Test.class.getResourceAsStream("/bug8803/foo.xml"); // deserialization final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream); final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, SCHEMA_CONTEXT, topContSchema); xmlParser.parse(reader); final NormalizedNode<?, ?> transformedInput = result.getResult(); assertNotNull(transformedInput); // serialization final StringWriter writer = new StringWriter(); final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(writer); final NormalizedNodeStreamWriter xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create( xmlStreamWriter, SCHEMA_CONTEXT); final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter( xmlNormalizedNodeStreamWriter); normalizedNodeWriter.write(transformedInput); normalizedNodeWriter.flush(); final String serializedXml = writer.toString(); assertFalse(serializedXml.isEmpty()); }
Example #9
Source File: SchemaNodeUtils.java From yangtools with Eclipse Public License 1.0 | 5 votes |
public static Optional<SchemaNode> getOriginalIfPossible(final SchemaNode node) { if (node instanceof DerivableSchemaNode) { @SuppressWarnings("unchecked") final Optional<SchemaNode> ret = (Optional<SchemaNode>) ((DerivableSchemaNode) node).getOriginal(); return ret; } return Optional.empty(); }
Example #10
Source File: YT841Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testFindDataSchemaNode() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/YT841/"); final Module foo = context.findModule(FOO).get(); final SchemaNode target = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, QName.create(FOO, "foo"), QName.create(FOO, "foo"), QName.create(FOO, "foo"), QName.create(FOO, "input"))); assertNotNull(target); }
Example #11
Source File: Bug5335Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void incorrectTest2() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-2"); assertNotNull(context); final SchemaPath schemaPath = SchemaPath.create(true, ROOT, PRESENCE_CONTAINER_F, MANDATORY_LEAF_B); final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath); assertNull(mandatoryLeaf); final String testLog = output.toString(); assertTrue(testLog.contains( "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target")); }
Example #12
Source File: EffectiveUsesRefineAndConstraintsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static void checkRefinedContainer(final SchemaContext result, final SchemaPath path) { SchemaNode containerInContainerNode = SchemaContextUtil.findDataSchemaNode(result, path); assertNotNull(containerInContainerNode); ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) containerInContainerNode; assertEquals(Optional.of("new reference"), containerSchemaNode.getReference()); assertEquals(Optional.of("new description"), containerSchemaNode.getDescription()); assertTrue(containerSchemaNode.isConfiguration()); assertTrue(containerSchemaNode.isPresenceContainer()); assertEquals(1, containerSchemaNode.getMustConstraints().size()); }
Example #13
Source File: SchemaTracker.java From yangtools with Eclipse Public License 1.0 | 5 votes |
public ChoiceSchemaNode startChoiceNode(final NodeIdentifier name) { LOG.debug("Enter choice {}", name); final SchemaNode schema = getSchema(name); checkArgument(schema instanceof ChoiceSchemaNode, "Node %s is not a choice", schema); schemaStack.push(schema); return (ChoiceSchemaNode)schema; }
Example #14
Source File: SchemaTracker.java From yangtools with Eclipse Public License 1.0 | 5 votes |
public LeafListSchemaNode leafSetEntryNode(final QName qname) { final Object parent = getParent(); if (parent instanceof LeafListSchemaNode) { return (LeafListSchemaNode) parent; } final SchemaNode child = SchemaUtils.findDataChildSchemaByQName((SchemaNode) parent, qname); checkArgument(child instanceof LeafListSchemaNode, "Node %s is neither a leaf-list nor currently in a leaf-list", child); return (LeafListSchemaNode) child; }
Example #15
Source File: SchemaTracker.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static SchemaNode findCaseByChild(final ChoiceSchemaNode parent, final QName qname) { for (final CaseSchemaNode caze : parent.getCases()) { final Optional<DataSchemaNode> potential = caze.findDataChildByName(qname); if (potential.isPresent()) { return caze; } } return null; }
Example #16
Source File: GroupingAndUsesStmtTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void usesAndRefinesTest() throws ReactorException { final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild() .addSources(MODULE, SUBMODULE, GROUPING_MODULE, USES_MODULE) .buildEffective(); assertNotNull(result); final Module testModule = result.findModules("foo").iterator().next(); final Collection<? extends UsesNode> usesNodes = testModule.getUses(); assertEquals(1, usesNodes.size()); UsesNode usesNode = usesNodes.iterator().next(); assertEquals("target", usesNode.getSourceGrouping().getQName().getLocalName()); assertEquals(1, usesNode.getAugmentations().size()); QName peer = QName.create(testModule.getQNameModule(), "peer"); ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(peer); assertNotNull(container); container = (ContainerSchemaNode) container.getDataChildByName(QName.create(peer, "destination")); assertEquals(1, container.getUses().size()); usesNode = container.getUses().iterator().next(); assertEquals("target", usesNode.getSourceGrouping().getQName().getLocalName()); final Map<Descendant, SchemaNode> refines = usesNode.getRefines(); assertEquals(4, refines.size()); assertEquals(ImmutableList.of( Descendant.of(QName.create(peer, "address")), Descendant.of(QName.create(peer, "port")), Descendant.of(QName.create(peer, "addresses")), Descendant.of(QName.create(peer, "addresses"), QName.create(peer, "id"))), new ArrayList<>(refines.keySet())); }
Example #17
Source File: EffectiveUsesRefineAndConstraintsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static void checkOriginalContainer(final SchemaContext result, final SchemaPath path) { SchemaNode containerInContainerNode = SchemaContextUtil.findDataSchemaNode(result, path); assertNotNull(containerInContainerNode); ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) containerInContainerNode; assertFalse(containerSchemaNode.getReference().isPresent()); assertFalse(containerSchemaNode.getDescription().isPresent()); assertTrue(containerSchemaNode.isConfiguration()); assertFalse(containerSchemaNode.isPresenceContainer()); assertEquals(0, containerSchemaNode.getMustConstraints().size()); }
Example #18
Source File: OpenconfigVersionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void nodeTest() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources("/openconfig-version/node-test", StatementParserMode.SEMVER_MODE); assertNotNull(context); Module foo = context.findModules(new URI("foo")).iterator().next(); Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next(); assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get()); assertEquals(SemVer.valueOf("2016.1.1"), foo.getSemanticVersion().get()); Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); assertEquals(SemVer.valueOf("2016.4.6"), bar.getSemanticVersion().get()); QName root = QName.create("foo", "2016-01-01", "foo-root"); QName container20160404 = QName.create("foo", "2016-01-01", "con20160404"); SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160404)); assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); QName container20160405 = QName.create("foo", "2016-01-01", "con20160405"); findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160405)); assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); QName container20160406 = QName.create("foo", "2016-01-01", "con20160406"); findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160406)); assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); QName container20170406 = QName.create("foo", "2016-01-01", "con20170406"); findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20170406)); assertNull(findDataSchemaNode); }
Example #19
Source File: Bug6669Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testInvalidAugment() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1"); assertNotNull(context); final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, ROOT, BAR, BAR_1, M)); assertNull(findDataSchemaNode); }
Example #20
Source File: SchemaContextUtilTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void findDataSchemaNodeTest2() { final GroupingDefinition grouping = getGroupingByName(myModule, "my-grouping"); final SchemaNode testNode = grouping.getDataChildByName(QName.create(myModule.getQNameModule(), "my-leaf-in-gouping2")); final PathExpression xpath = new PathExpressionImpl("my:my-grouping/my:my-leaf-in-gouping2", true); final SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, myModule, xpath); assertNotNull(foundNode); assertNotNull(testNode); assertEquals(testNode, foundNode); }
Example #21
Source File: LeafrefStaticAnalysisTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testFooOuterId() { final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(QName.create(FOO, "outer-id")).get(); final SchemaNode found = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf, ((LeafrefTypeDefinition) leaf.getType()).getPathStatement()); assertThat(found, isA(LeafSchemaNode.class)); assertEquals(SchemaPath.create(true, FOO, QName.create(FOO, "id")), found.getPath()); }
Example #22
Source File: LeafrefStaticAnalysisTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testGrpIndirect() { final LeafSchemaNode leaf = (LeafSchemaNode) grp.findDataChildByName(QName.create(FOO, "indirect")).get(); final SchemaNode found = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf, ((LeafrefTypeDefinition) leaf.getType()).getPathStatement()); assertThat(found, isA(LeafSchemaNode.class)); assertEquals(QName.create(FOO, "prop"), found.getQName()); }
Example #23
Source File: LeafrefStaticAnalysisTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testFooIndirect() { final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(QName.create(FOO, "indirect")).get(); final SchemaNode found = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf, ((LeafrefTypeDefinition) leaf.getType()).getPathStatement()); assertThat(found, isA(LeafSchemaNode.class)); assertEquals(QName.create(FOO, "prop"), found.getQName()); }
Example #24
Source File: SchemaNodeUtilsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testHandleNodeGetOriginalIfPossible() { Optional<DerivableSchemaNode> of = Optional.of(derivableNode); doReturn(of).when(derivableNode).getOriginal(); Optional<SchemaNode> originalIfPossible = SchemaNodeUtils .getOriginalIfPossible(derivableNode); assertNotNull(originalIfPossible); assertThat(originalIfPossible, instanceOf(Optional.class)); }
Example #25
Source File: Bug5437Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5437"); assertNotNull(context); QName root = QName.create(NS, REV, "root"); QName leafRef2 = QName.create(NS, REV, "leaf-ref-2"); QName conGrp = QName.create(NS, REV, "con-grp"); QName leafRef = QName.create(NS, REV, "leaf-ref"); SchemaPath leafRefPath = SchemaPath.create(true, root, conGrp, leafRef); SchemaPath leafRef2Path = SchemaPath.create(true, root, leafRef2); SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, leafRefPath); SchemaNode findDataSchemaNode2 = SchemaContextUtil.findDataSchemaNode(context, leafRef2Path); assertThat(findDataSchemaNode, isA(LeafSchemaNode.class)); assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class)); LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode; LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2; assertThat(leafRefNode.getType(), isA(LeafrefTypeDefinition.class)); assertThat(leafRefNode2.getType(), isA(LeafrefTypeDefinition.class)); TypeDefinition<?> baseTypeForLeafRef = SchemaContextUtil.getBaseTypeForLeafRef( (LeafrefTypeDefinition) leafRefNode.getType(), context, leafRefNode); TypeDefinition<?> baseTypeForLeafRef2 = SchemaContextUtil.getBaseTypeForLeafRef( (LeafrefTypeDefinition) leafRefNode2.getType(), context, leafRefNode2); assertThat(baseTypeForLeafRef, isA(BinaryTypeDefinition.class)); assertThat(baseTypeForLeafRef2, isA(Int16TypeDefinition.class)); }
Example #26
Source File: SchemaContextUtil.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Beta public static SchemaNode findDataTreeSchemaNode(final SchemaContext ctx, final QNameModule localModule, final PathExpression absPath) { final Steps pathSteps = absPath.getSteps(); if (pathSteps instanceof LocationPathSteps) { return findDataTreeSchemaNode(ctx, localModule, ((LocationPathSteps) pathSteps).getLocationPath()); } // We would need a reference schema node and no, we do not want to use SchemaContext in its SchemaNode capacity checkArgument(!(pathSteps instanceof DerefSteps), "No reference node for steps %s", pathSteps); // We are missing proper API alignment, if this ever triggers throw new IllegalStateException("Unsupported path " + pathSteps); }
Example #27
Source File: UsesEffectiveStatementImpl.java From yangtools with Eclipse Public License 1.0 | 5 votes |
UsesEffectiveStatementImpl(final StmtContext<QName, UsesStatement, UsesEffectiveStatement> ctx) { super(ctx); // initGroupingPath final StmtContext<?, GroupingStatement, GroupingEffectiveStatement> grpCtx = ctx.getFromNamespace(GroupingNamespace.class, ctx.coerceStatementArgument()); this.sourceGrouping = (GroupingDefinition) grpCtx.buildEffective(); // initCopyType addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES); // initSubstatementCollections final Set<AugmentationSchemaNode> augmentationsInit = new LinkedHashSet<>(); final Map<Descendant, SchemaNode> refinesInit = new LinkedHashMap<>(); for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) { if (effectiveStatement instanceof AugmentationSchemaNode) { final AugmentationSchemaNode augmentationSchema = (AugmentationSchemaNode) effectiveStatement; augmentationsInit.add(augmentationSchema); } if (effectiveStatement instanceof RefineEffectiveStatementImpl) { final RefineEffectiveStatementImpl refineStmt = (RefineEffectiveStatementImpl) effectiveStatement; refinesInit.put(refineStmt.argument(), refineStmt.getRefineTargetNode()); } } this.augmentations = ImmutableSet.copyOf(augmentationsInit); this.refines = ImmutableMap.copyOf(refinesInit); whenCondition = findFirstEffectiveSubstatementArgument(WhenEffectiveStatement.class).orElse(null); }
Example #28
Source File: Bug6669Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testValidAugment3() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test3"); assertNotNull(context); final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L)); assertTrue(findDataSchemaNode instanceof ListSchemaNode); }
Example #29
Source File: Bug6883Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static AnydataSchemaNode assertAnyData(final SchemaContext context, final Iterable<String> localNamesPath) { final Iterable<QName> qNames = Iterables.transform(localNamesPath, localName -> QName.create(FOO_NS, localName)); final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true)); assertTrue(findDataSchemaNode instanceof AnydataSchemaNode); return (AnydataSchemaNode) findDataSchemaNode; }
Example #30
Source File: Bug5335Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void incorrectTest1() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-1"); assertNotNull(context); final SchemaPath schemaPath = SchemaPath.create(true, ROOT, NON_PRESENCE_CONTAINER_B, MANDATORY_LEAF_B); final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath); assertNull(mandatoryLeaf); final String testLog = output.toString(); assertTrue(testLog.contains( "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target")); }