Java Code Examples for org.opendaylight.yangtools.yang.model.api.Module#getImports()
The following examples show how to use
org.opendaylight.yangtools.yang.model.api.Module#getImports() .
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 |
/** * Method will attempt to resolve and provide Module reference for specified module prefix. Each Yang module could * contains multiple imports which MUST be associated with corresponding module prefix. The method simply looks into * module imports and returns the module that is bounded with specified prefix. If the prefix is not present * in module or the prefixed module is not present in specified Schema Context, the method will return {@code null}. * <br> * If String prefix is the same as prefix of the specified Module the reference to this module is returned.<br> * * @param context Schema Context * @param module Yang Module * @param prefix Module Prefix * @return Module for given prefix in specified Schema Context if is present, otherwise returns <code>null</code> * @throws NullPointerException if any arguments are null */ private static Module resolveModuleForPrefix(final SchemaContext context, final Module module, final String prefix) { requireNonNull(context, "context"); if (prefix.equals(module.getPrefix())) { return module; } for (final ModuleImport mi : module.getImports()) { if (prefix.equals(mi.getPrefix())) { return context.findModule(mi.getModuleName(), mi.getRevision()).orElse(null); } } return null; }
Example 2
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkInterfacesModuleSimpleTest(final SchemaContext context, final Revision rev20100924, final QName dateTimeTypeDef20100924) { URI interfacesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-interfaces"); Revision rev20121115 = Revision.of("2012-11-15"); final QNameModule interfacesNS20121115 = QNameModule.create(interfacesNS, rev20121115); QName lastChange = QName.create(interfacesNS20121115, "last-change"); Module interfacesModule20121115 = context.findModule("ietf-interfaces", rev20121115).get(); DataSchemaNode leafLastChange = interfacesModule20121115.getDataChildByName(lastChange); assertNotNull(leafLastChange); assertTrue(leafLastChange instanceof LeafSchemaNode); QName lastChangeTypeQName = ((LeafSchemaNode) leafLastChange).getType().getQName(); assertEquals(dateTimeTypeDef20100924, lastChangeTypeQName); Collection<? extends ModuleImport> imports = interfacesModule20121115.getImports(); assertEquals(1, imports.size()); ModuleImport interfacesImport = imports.iterator().next(); assertEquals("ietf-yang-types", interfacesImport.getModuleName()); assertEquals(Optional.of(rev20100924), interfacesImport.getRevision()); }
Example 3
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkNetconfMonitoringModuleSimpleTest(final SchemaContext context, final Revision rev20130715, final QName dateTimeTypeDef20130715) { URI monitoringNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"); final QNameModule monitoring19700101 = QNameModule.create(monitoringNS); QName lockedTime = QName.create(monitoring19700101, "locked-time"); Module monitoringModule19700101 = context.findModule("ietf-netconf-monitoring").get(); DataSchemaNode leafLockedTime = monitoringModule19700101.getDataChildByName(lockedTime); assertNotNull(leafLockedTime); assertTrue(leafLockedTime instanceof LeafSchemaNode); QName lockedTimeTypeQName = ((LeafSchemaNode) leafLockedTime).getType().getQName(); assertEquals(dateTimeTypeDef20130715, lockedTimeTypeQName); Collection<? extends ModuleImport> imports = monitoringModule19700101.getImports(); assertEquals(1, imports.size()); ModuleImport monitoringImport = imports.iterator().next(); assertEquals("ietf-yang-types", monitoringImport.getModuleName()); assertEquals(Optional.of(rev20130715), monitoringImport.getRevision()); }
Example 4
Source File: FilteringSchemaContextProxy.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private boolean checkModuleDependency(final Module module, final Collection<ModuleId> rootModules) { for (ModuleId rootModule : rootModules) { if (rootModule.equals(new ModuleId(module.getName(), module.getRevision()))) { return true; } //handling/checking imports regarding root modules for (ModuleImport moduleImport : module.getImports()) { if (moduleImport.getModuleName().equals(rootModule.getName())) { return moduleImport.getRevision().isEmpty() || moduleImport.getRevision().equals(rootModule.getRev()); } } //submodules handling for (Module moduleSub : module.getSubmodules()) { return checkModuleDependency(moduleSub, rootModules); } } return false; }
Example 5
Source File: YinFileImportStmtTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testImport() throws ParseException { Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get(); assertNotNull(testModule); Collection<? extends ModuleImport> imports = testModule.getImports(); assertEquals(2, imports.size()); Iterator<? extends ModuleImport> importsIterator = imports.iterator(); ModuleImport moduleImport = importsIterator.next(); assertThat(moduleImport.getModuleName(), anyOf(is("ietf-yang-types"), is("ietf-inet-types"))); assertThat(moduleImport.getPrefix(), anyOf(is("yang"), is("inet"))); moduleImport = importsIterator.next(); assertThat(moduleImport.getModuleName(), anyOf(is("ietf-yang-types"), is("ietf-inet-types"))); assertThat(moduleImport.getPrefix(), anyOf(is("yang"), is("inet"))); }
Example 6
Source File: Bug9005Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void test() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug9005"); assertNotNull(context); final Module foo = context.findModule("foo", Revision.of("2017-07-07")).get(); final Collection<? extends ModuleImport> imports = foo.getImports(); assertEquals(1, imports.size()); final ModuleImport imp1 = imports.iterator().next(); assertEquals("bar-2", imp1.getModuleName()); assertEquals("bar", imp1.getPrefix()); assertEquals(Revision.ofNullable("2000-01-02"), imp1.getRevision()); final Collection<? extends Module> submodules = foo.getSubmodules(); assertEquals(1, submodules.size()); final Module submodule = submodules.iterator().next(); final Collection<? extends ModuleImport> subImports = submodule.getImports(); assertEquals(1, subImports.size()); final ModuleImport subImp1 = subImports.iterator().next(); assertEquals("bar-1", subImp1.getModuleName()); assertEquals("bar", subImp1.getPrefix()); assertEquals(Revision.ofNullable("2000-01-01"), subImp1.getRevision()); }
Example 7
Source File: LeafrefXPathStringParsingPathArgumentBuilder.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private QName createQName(final String prefix, final String localName) { final Module module = schemaContext.findModule(schemaNode.getQName().getModule()).get(); if (prefix.isEmpty() || module.getPrefix().equals(prefix)) { return QName.create(module.getQNameModule(), localName); } for (final ModuleImport moduleImport : module.getImports()) { if (prefix.equals(moduleImport.getPrefix())) { final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); return QName.create(importedModule.getQNameModule(),localName); } } throw new IllegalArgumentException(String.format("Failed to lookup a module for prefix %s", prefix)); }
Example 8
Source File: Bug8597Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void test() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8597"); assertNotNull(context); final Module foo = context.findModule("foo").get(); for (final ModuleImport moduleImport : foo.getImports()) { switch (moduleImport.getModuleName()) { case "bar": assertEquals(Revision.ofNullable("1970-01-01"), moduleImport.getRevision()); assertEquals(Optional.of("bar-ref"), moduleImport.getReference()); assertEquals(Optional.of("bar-desc"), moduleImport.getDescription()); break; case "baz": assertEquals(Revision.ofNullable("2010-10-10"), moduleImport.getRevision()); assertEquals(Optional.of("baz-ref"), moduleImport.getReference()); assertEquals(Optional.of("baz-desc"), moduleImport.getDescription()); break; default: fail("Module 'foo' should only contains import of module 'bar' and 'baz'"); } } }
Example 9
Source File: PrefixConverters.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Create a prefix {@link Converter} for {@link XPathExpressionException} defined in a particular YANG * {@link Module} .Instantiation requires establishing how a module's imports are mapped to actual modules * and their namespaces. This information is cached and used for improved lookups. * * @param ctx A SchemaContext * @param module Module in which the XPath is defined * @return A new Converter */ public static @NonNull Converter<String, QNameModule> create(final SchemaContext ctx, final Module module) { // Always check for null ctx requireNonNull(ctx, "Schema context may not be null"); // Use immutable map builder for detection of duplicates (which should never occur) final Builder<String, QNameModule> b = ImmutableBiMap.builder(); b.put(module.getPrefix(), module.getQNameModule()); for (ModuleImport i : module.getImports()) { final Optional<? extends Module> mod = ctx.findModule(i.getModuleName(), i.getRevision()); checkArgument(mod.isPresent(), "Unsatisfied import of %s by module %s", i, module); b.put(i.getPrefix(), mod.get().getQNameModule()); } return Maps.asConverter(b.build()); }
Example 10
Source File: OpenconfigVersionMultipleImportTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static Module findImportedModule(final SchemaContext context, final Module rootModule, final String importedModuleName) { ModuleImport requestedModuleImport = null; for (ModuleImport moduleImport : rootModule.getImports()) { if (moduleImport.getModuleName().equals(importedModuleName)) { requestedModuleImport = moduleImport; break; } } return context.findModule(requestedModuleImport.getModuleName(), requestedModuleImport.getRevision()).get(); }
Example 11
Source File: FilteringSchemaContextProxy.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static Collection<Module> getImportedModules(final Map<ModuleId, ? extends Module> allModules, final Collection<? extends Module> baseModules, final TreeMultimap<String, Module> nameToModulesAll) { List<Module> relatedModules = new LinkedList<>(); for (Module module : baseModules) { for (ModuleImport moduleImport : module.getImports()) { Optional<Revision> revisionDate = moduleImport.getRevision(); if (revisionDate.isEmpty()) { revisionDate = nameToModulesAll.get(moduleImport.getModuleName()).first().getRevision(); } ModuleId key = new ModuleId(moduleImport.getModuleName(), revisionDate); Module importedModule = allModules.get(key); Preconditions.checkArgument(importedModule != null, "Invalid schema, cannot find imported module: %s from module: %s, %s, modules:%s", key, module.getQNameModule(), module.getName(), allModules); relatedModules.add(importedModule); //calling imports recursive relatedModules.addAll(getImportedModules(allModules, Collections.singleton(importedModule), nameToModulesAll)); } } return relatedModules; }
Example 12
Source File: ModuleDependencySort.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static Collection<? extends ModuleImport> allImports(final Module mod) { if (mod.getSubmodules().isEmpty()) { return mod.getImports(); } final Collection<ModuleImport> concat = new LinkedHashSet<>(); concat.addAll(mod.getImports()); for (Module sub : mod.getSubmodules()) { concat.addAll(sub.getImports()); } return concat; }
Example 13
Source File: YangFunctionContext.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static IdentitySchemaNode getIdentitySchemaNodeFromString(final String identity, final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) { final List<String> identityPrefixAndName = COLON_SPLITTER.splitToList(identity); final Module module = schemaContext.findModule(correspondingSchemaNode.getQName().getModule()).get(); if (identityPrefixAndName.size() == 2) { // prefix of local module if (identityPrefixAndName.get(0).equals(module.getPrefix())) { return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(), identityPrefixAndName.get(1))); } // prefix of imported module for (final ModuleImport moduleImport : module.getImports()) { if (identityPrefixAndName.get(0).equals(moduleImport.getPrefix())) { final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); return findIdentitySchemaNodeInModule(importedModule, QName.create( importedModule.getQNameModule(), identityPrefixAndName.get(1))); } } throw new IllegalArgumentException(String.format("Cannot resolve prefix '%s' from identity '%s'.", identityPrefixAndName.get(0), identity)); } if (identityPrefixAndName.size() == 1) { // without prefix return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(), identityPrefixAndName.get(0))); } throw new IllegalArgumentException(String.format("Malformed identity argument: %s.", identity)); }
Example 14
Source File: Bug6491Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static void testRevision(final String path, final Revision moduleRevision, final Optional<Revision> importedRevision) throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6491/".concat(path)); assertNotNull(context); final Module module = context.findModule("bar", moduleRevision).get(); final Collection<? extends ModuleImport> imports = module.getImports(); assertNotNull(imports); assertEquals(1, imports.size()); assertEquals(importedRevision, imports.iterator().next().getRevision()); }
Example 15
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static void checkInterfacesModuleFullTest(final SchemaContext context, final Revision rev20100924, final QName dateTimeTypeDef20100924) { Revision rev20121115 = Revision.of("2012-11-15"); Module interfacesModule20121115 = context.findModule("ietf-interfaces", rev20121115).get(); Collection<? extends ModuleImport> imports = interfacesModule20121115.getImports(); assertEquals(1, imports.size()); ModuleImport interfacesImport = imports.iterator().next(); assertEquals("ietf-yang-types", interfacesImport.getModuleName()); assertEquals(Optional.of(rev20100924), interfacesImport.getRevision()); }
Example 16
Source File: StmtTestUtils.java From yangtools with Eclipse Public License 1.0 | 5 votes |
public static Module findImportedModule(final SchemaContext context, final Module rootModule, final String importedModuleName) { ModuleImport requestedModuleImport = null; for (final ModuleImport moduleImport : rootModule.getImports()) { if (moduleImport.getModuleName().equals(importedModuleName)) { requestedModuleImport = moduleImport; break; } } return context.findModule(requestedModuleImport.getModuleName(), requestedModuleImport.getRevision()) .orElse(null); }
Example 17
Source File: YangParserIdentityTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testParsingImportPrefixIdentityTestModule() throws Exception { Module module = TestUtils.findModule(TestUtils.loadModules(getClass().getResource("/identity/import").toURI()), "prefiximportidentitytest").get(); Collection<? extends ModuleImport> imports = module.getImports(); assertEquals(imports.size(), 1); ModuleImport dummy = TestUtils.findImport(imports, "dummy"); assertNotEquals(dummy.getPrefix(), module.getPrefix()); }
Example 18
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static void checkNetconfMonitoringModuleFullTest(final SchemaContext context, final Revision rev20130715, final QName dateTimeTypeDef20130715) { Revision rev20101004 = Revision.of("2010-10-04"); Module monitoringModule20101004 = context.findModule("ietf-netconf-monitoring", rev20101004).get(); Collection<? extends ModuleImport> imports = monitoringModule20101004.getImports(); assertEquals(2, imports.size()); for (ModuleImport monitoringImport : imports) { if (monitoringImport.getModuleName().equals("ietf-yang-types")) { assertEquals(Optional.of(rev20130715), monitoringImport.getRevision()); } } }
Example 19
Source File: EffectiveModuleTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Test public void effectiveBuildTest() throws SourceException, ReactorException { SchemaContext result = RFC7950Reactors.defaultReactor().newBuild() .addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE) .buildEffective(); assertNotNull(result); Module rootModule = result.findModules("root").iterator().next(); assertNotNull(rootModule); assertEquals("root-pref", rootModule.getPrefix()); assertEquals(YangVersion.VERSION_1, rootModule.getYangVersion()); assertEquals(Optional.of("cisco"), rootModule.getOrganization()); assertEquals(Optional.of("cisco email"), rootModule.getContact()); final ContainerSchemaNode contSchemaNode = (ContainerSchemaNode) rootModule.getDataChildByName(CONT); assertNotNull(contSchemaNode); final Collection<? extends AugmentationSchemaNode> augmentations = rootModule.getAugmentations(); assertEquals(1, augmentations.size()); assertEquals(Absolute.of(CONT), augmentations.iterator().next().getTargetPath()); final Collection<? extends ModuleImport> imports = rootModule.getImports(); assertEquals(1, imports.size()); final ModuleImport importStmt = imports.iterator().next(); assertNotNull(importStmt); assertEquals("imported", importStmt.getModuleName()); assertEquals(Optional.of(REVISION), importStmt.getRevision()); assertEquals("imp-pref", importStmt.getPrefix()); final Collection<? extends Module> submodules = rootModule.getSubmodules(); assertEquals(1, submodules.size()); assertEquals("submod", submodules.iterator().next().getName()); final Collection<? extends NotificationDefinition> notifications = rootModule.getNotifications(); assertEquals(1, notifications.size()); assertEquals("notif1", notifications.iterator().next().getQName().getLocalName()); final Collection<? extends RpcDefinition> rpcs = rootModule.getRpcs(); assertEquals(1, rpcs.size()); assertEquals("rpc1", rpcs.iterator().next().getQName().getLocalName()); final Collection<? extends Deviation> deviations = rootModule.getDeviations(); assertEquals(1, deviations.size()); final Deviation deviationStmt = deviations.iterator().next(); assertNotNull(deviationStmt); final QNameModule importedModuleQName = QNameModule.create(URI.create("imported"), REVISION); final QName importedContQName = QName.create(importedModuleQName, "cont"); assertEquals(Absolute.of(importedContQName), deviationStmt.getTargetPath()); assertEquals(DeviateKind.ADD, deviationStmt.getDeviates().iterator().next().getDeviateType()); assertEquals(Optional.of("deviate reference"), deviationStmt.getReference()); final Collection<? extends IdentitySchemaNode> identities = rootModule.getIdentities(); assertEquals(1, identities.size()); assertEquals("identity1", identities.iterator().next().getQName().getLocalName()); final Collection<? extends FeatureDefinition> features = rootModule.getFeatures(); assertEquals(1, features.size()); final FeatureDefinition featureStmt = features.iterator().next(); assertNotNull(featureStmt); assertEquals(FEATURE1, featureStmt.getQName()); assertEquals(FEATURE1_SCHEMA_PATH, featureStmt.getPath()); assertEquals(Optional.of("feature1 description"), featureStmt.getDescription()); assertEquals(Optional.of("feature1 reference"), featureStmt.getReference()); assertEquals(Status.CURRENT, featureStmt.getStatus()); final Collection<? extends ExtensionDefinition> extensionSchemaNodes = rootModule.getExtensionSchemaNodes(); assertEquals(1, extensionSchemaNodes.size()); assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName()); }