private static ModuleImport getModuleImport(final Module targetModule, final String prefix) { return targetModule.getImports().stream() .filter(imp -> prefix.equals(imp.getPrefix())).findFirst().orElse(null); } }
private static ModuleImport findModuleImport(final Module module, final String prefix) { for (ModuleImport moduleImport : module.getImports()) { if (moduleImport.getPrefix().equals(prefix)) { return moduleImport; } } throw new IllegalStateException(format("Import not found with prefix %s in %s", prefix, module)); }
private static ModuleImport getModuleImport(final Module targetModule, final String prefix) { return targetModule.getImports().stream() .filter(imp -> prefix.equals(imp.getPrefix())).findFirst().orElse(null); } }
private static String getConfigModulePrefixFromImport(final Module currentModule) { for (ModuleImport currentImport : currentModule.getImports()) { if (currentImport.getModuleName().equals(ConfigConstants.CONFIG_MODULE)) { return currentImport.getPrefix(); } } throw new IllegalArgumentException("Cannot find import " + ConfigConstants.CONFIG_MODULE + " in " + currentModule); }
private Module findModuleFromImports(final Set<ModuleImport> imports, final String prefix) { for (final ModuleImport imp : imports) { if (imp.getPrefix().equals(prefix)) { return schemaContext.findModule(imp.getModuleName(), imp.getRevision()).orElse(null); } } return null; }
private Module findModuleFromImports(final Set<ModuleImport> imports, final String prefix) { for (final ModuleImport imp : imports) { if (imp.getPrefix().equals(prefix)) { return schemaContext.findModuleByName(imp.getModuleName(), imp.getRevision()); } } return null; }
private static Map<String, URI> prefixToNamespace(final SchemaContext ctx, final Module module) { final BiMap<String, URI> prefixMap = HashBiMap.create(module.getImports().size() + 1); prefixMap.put(module.getPrefix(), module.getNamespace()); for (final ModuleImport imp : module.getImports()) { final String prefix = imp.getPrefix(); final URI namespace = getModuleNamespace(ctx, imp.getModuleName()); prefixMap.put(prefix, namespace); } return prefixMap; }
private static Map<String, URI> prefixToNamespace(final SchemaContext ctx, final Module module) { final BiMap<String, URI> prefixMap = HashBiMap.create(module.getImports().size() + 1); prefixMap.put(module.getPrefix(), module.getNamespace()); for (final ModuleImport imp : module.getImports()) { final String prefix = imp.getPrefix(); final URI namespace = getModuleNamespace(ctx, imp.getModuleName()); prefixMap.put(prefix, namespace); } return prefixMap; }
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)); }
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)); }
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)); }
if (prefix.equals(mi.getPrefix())) { return context.findModule(mi.getModuleName(), mi.getRevision()).orElse(null);
if (prefix.equals(mi.getPrefix())) { return context.findModule(mi.getModuleName(), mi.getRevision()).orElse(null);
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)); }
private static Object qnameDomValueFromString(final Codec<Object, Object> codec, final DataSchemaNode schema, final String defaultValue, final SchemaContext schemaContext) { int prefixEndIndex = defaultValue.indexOf(':'); QName qname; if (prefixEndIndex != -1) { String defaultValuePrefix = defaultValue.substring(0, prefixEndIndex); Module module = schemaContext.findModule(schema.getQName().getModule()).get(); if (module.getPrefix().equals(defaultValuePrefix)) { qname = QName.create(module.getQNameModule(), defaultValue.substring(prefixEndIndex + 1)); return codec.deserialize(qname); } Set<ModuleImport> imports = module.getImports(); for (ModuleImport moduleImport : imports) { if (moduleImport.getPrefix().equals(defaultValuePrefix)) { Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); qname = QName.create(importedModule.getQNameModule(), defaultValue.substring(prefixEndIndex + 1)); return codec.deserialize(qname); } } return null; } qname = QName.create(schema.getQName(), defaultValue); return codec.deserialize(qname); }
private static Object qnameDomValueFromString(final Codec<Object, Object> codec, final DataSchemaNode schema, final String defaultValue, final SchemaContext schemaContext) { final int prefixEndIndex = defaultValue.indexOf(':'); if (prefixEndIndex != -1) { final String defaultValuePrefix = defaultValue.substring(0, prefixEndIndex); final Module module = schemaContext.findModule(schema.getQName().getModule()).get(); if (module.getPrefix().equals(defaultValuePrefix)) { return codec.deserialize(QName.create(module.getQNameModule(), defaultValue.substring(prefixEndIndex + 1))); } final Set<ModuleImport> imports = module.getImports(); for (final ModuleImport moduleImport : imports) { if (moduleImport.getPrefix().equals(defaultValuePrefix)) { final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get(); return codec.deserialize(QName.create(importedModule.getQNameModule(), defaultValue.substring(prefixEndIndex + 1))); } } return null; } return codec.deserialize(QName.create(schema.getQName(), defaultValue)); }
private void emitImport(final ModuleImport importNode) { super.writer.startImportNode(importNode.getModuleName()); emitDocumentedNode(importNode); emitPrefixNode(importNode.getPrefix()); importNode.getRevision().ifPresent(this::emitRevisionDateNode); super.writer.endNode(); }
/** * 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<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()); } }
/** * 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<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()); } }
_builder.append(_moduleName_1, ""); _builder.append(" { prefix \""); String _prefix = moduleImport.getPrefix(); _builder.append(_prefix, ""); _builder.append("\"; }");