*/
package org.opendaylight.yangtools.yang.model.api;
+import java.net.URI;
+import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.opendaylight.yangtools.concepts.SemVer;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.YangVersion;
/**
</code>
*/
@Immutable
-public interface Module extends DataNodeContainer, ModuleIdentifier, NotificationNodeContainer {
+public interface Module extends DataNodeContainer, NotificationNodeContainer {
/**
* Default semantic version of Module.
*/
SemVer DEFAULT_SEMANTIC_VERSION = SemVer.create(0, 0, 0);
+ /**
+ * Returns the name of the module which is specified as argument of YANG
+ * {@link Module <b><font color="#FF0000">module</font></b>} keyword.
+ *
+ * @return string with the name of the module
+ */
+ String getName();
+
+ /**
+ * Returns a {@link QNameModule}, which contains the namespace and
+ * the revision of the module.
+ *
+ * @return QNameModule identifier.
+ */
+ QNameModule getQNameModule();
+
+ /**
+ * Returns the namespace of the module which is specified as argument of
+ * YANG {@link Module <b><font color="#00FF00">namespace</font></b>}
+ * keyword. If you need both namespace and revision, please consider using
+ * {@link #getQNameModule()}.
+ *
+ * @return URI format of the namespace of the module
+ */
+ default URI getNamespace() {
+ return getQNameModule().getNamespace();
+ }
+
+ /**
+ * Returns the revision date for the module. If you need both namespace and
+ * revision, please consider using {@link #getQNameModule()}.
+ *
+ * @return date of the module revision which is specified as argument of
+ * YANG {@link Module <b><font color="#339900">revison</font></b>}
+ * keyword
+ */
+ // FIXME: BUG-4688: should return Optional<Revision>
+ @Nullable default Date getRevision() {
+ return getQNameModule().getRevision();
+ }
+
+ /**
+ * Returns the semantic version of yang module.
+ *
+ * <p>
+ * If the semantic version is not specified, default semantic version of
+ * module is returned.
+ *
+ * @return SemVer semantic version of yang module which is specified as
+ * argument of
+ * (urn:opendaylight:yang:extension:semantic-version?revision
+ * =2016-02-02)semantic-version statement
+ */
+ // FIXME: Should return Optional<SemVer>
+ default SemVer getSemanticVersion() {
+ return Module.DEFAULT_SEMANTIC_VERSION;
+ }
+
/**
* Returns the prefix of the module.
*
import java.util.Date;
import org.opendaylight.yangtools.concepts.SemVer;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-
+/**
+ * Module identifier. This "identifier" is deprecated and is to be removed in 2.0.0.
+ * @author Robert Varga
+ *
+ * @deprecated Use {@link SourceIdentifier} instead.
+ */
+@Deprecated
public interface ModuleIdentifier {
/**
* Returns a {@link QNameModule}, which contains the namespace and
}
return null;
}
-
- /**
- * Get all module and submodule identifiers.
- */
- Set<ModuleIdentifier> getAllModuleIdentifiers();
}
import com.google.common.base.Strings;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Lists;
@Override
public String toString() {
-
return String.format("ModuleId{name='%s', rev=%s}",name,rev);
}
}
-
- @Override
- public Set<ModuleIdentifier> getAllModuleIdentifiers() {
- return ImmutableSet.copyOf(filteredModules);
- }
}
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
return null;
}
+ /**
+ * Extract the identifiers of all modules and submodules which were used to create a particular SchemaContext.
+ *
+ * @param context SchemaContext to be examined
+ * @return Set of ModuleIdentifiers.
+ */
+ public static Set<ModuleIdentifier> getConstituentModuleIdentifiers(final SchemaContext context) {
+ final Set<ModuleIdentifier> ret = new HashSet<>();
+
+ for (Module module : context.getModules()) {
+ ret.add(moduleToIdentifier(module));
+
+ for (Module submodule : module.getSubmodules()) {
+ ret.add(moduleToIdentifier(submodule));
+ }
+ }
+
+ return ret;
+ }
+
+ private static ModuleIdentifier moduleToIdentifier(final Module module) {
+ return ModuleIdentifierImpl.create(module.getName(), Optional.of(module.getNamespace()),
+ Optional.of(module.getRevision()));
+ }
+
private static SchemaNode findNodeInModule(final Module module, final Iterable<QName> path) {
Preconditions.checkArgument(module != null, "Parent reference cannot be NULL");
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
import java.net.URI;
-import java.util.HashSet;
-import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
/**
* Simple subclass of {@link AbstractSchemaContext} which performs some amount of indexing to speed up common
public class SimpleSchemaContext extends AbstractSchemaContext {
private final SetMultimap<URI, Module> namespaceToModules;
private final SetMultimap<String, Module> nameToModules;
- private final Set<ModuleIdentifier> moduleIdentifiers;
private final Set<Module> modules;
protected SimpleSchemaContext(final Set<Module> modules) {
AbstractSchemaContext::createModuleSet);
final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(),
AbstractSchemaContext::createModuleSet);
- final Set<ModuleIdentifier> modIdBuilder = new HashSet<>();
for (Module m : modules) {
nameMap.put(m.getName(), m);
nsMap.put(m.getNamespace(), m);
- modIdBuilder.add(ModuleIdentifierImpl.create(m.getName(), Optional.of(m.getNamespace()),
- Optional.of(m.getRevision())));
- resolveSubmoduleIdentifiers(m.getSubmodules(), modIdBuilder);
}
namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
nameToModules = ImmutableSetMultimap.copyOf(nameMap);
- moduleIdentifiers = ImmutableSet.copyOf(modIdBuilder);
}
/**
return new SimpleSchemaContext(modules);
}
- private static void resolveSubmoduleIdentifiers(final Set<Module> submodules,
- final Set<ModuleIdentifier> modIdBuilder) {
- for (Module submodule : submodules) {
- modIdBuilder.add(ModuleIdentifierImpl.create(submodule.getName(),
- Optional.of(submodule.getNamespace()), Optional.of(submodule.getRevision())));
- }
- }
-
@Override
public final Set<Module> getModules() {
return modules;
}
- @Override
- public final Set<ModuleIdentifier> getAllModuleIdentifiers() {
- return moduleIdentifiers;
- }
-
@Override
public final String toString() {
return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
public class Bug6961Test {
final Set<ModuleIdentifier> testSet = ImmutableSet.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz);
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6961/");
assertNotNull(context);
- final Set<ModuleIdentifier> allModuleIdentifiers = context.getAllModuleIdentifiers();
+ final Set<ModuleIdentifier> allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
assertNotNull(allModuleIdentifiers);
assertEquals(6, allModuleIdentifiers.size());
final SchemaContext schemaContext = SimpleSchemaContext.forModules(context.getModules());
assertNotNull(schemaContext);
- final Set<ModuleIdentifier> allModuleIdentifiersResolved = schemaContext.getAllModuleIdentifiers();
+ final Set<ModuleIdentifier> allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
+ schemaContext);
assertNotNull(allModuleIdentifiersResolved);
assertEquals(6, allModuleIdentifiersResolved.size());
assertEquals(allModuleIdentifiersResolved, allModuleIdentifiers);
"foo", SimpleDateFormatUtil.getRevisionFormat().parse("2016-09-21"));
assertNotNull(fooModule);
- assertEquals(3, schemaContext.getAllModuleIdentifiers().size());
+ assertEquals(3, schemaContext.getModules().size());
assertEquals(3, ((EffectiveSchemaContext) schemaContext).getRootDeclaredStatements().size());
assertEquals(3,((EffectiveSchemaContext) schemaContext).getRootEffectiveStatements().size());