import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import org.opendaylight.yangtools.concepts.SemVer;
+import org.opendaylight.yangtools.yang.common.YangVersion;
/**
* This interface contains the methods for getting the data from the YANG
String getPrefix();
/**
- * Returns the YANG version. Default value is 1.
+ * Returns the YANG version.
*
- * @return string with the module YANG version which is specified as
- * argument of YANG {@link Module <b> <font
- * color="#8b4513">yang-version</font></b>} keyword
+ * @return YANG version of this module.
*/
- // FIXME: version 2.0.0: return YangVersion
- String getYangVersion();
+ YangVersion getYangVersion();
/**
* Returns the module description.
* augment) we can get declared form i.e. ModuleStatement and then
* use DeclaredSchemaContextEmitter
*/
- new DeclaredSchemaContextEmitter(yangSchemaWriter, extensions,
- YangVersion.parse(module.getYangVersion()).orElse(null))
- .emitModule(((EffectiveStatement<?, ?>) module).getDeclared());
+ new DeclaredSchemaContextEmitter(yangSchemaWriter, extensions, module.getYangVersion())
+ .emitModule(((EffectiveStatement<?, ?>) module).getDeclared());
} else {
/*
* if we don't have access to declared form of supplied module or we
* want to emit also instantiated statements (e.g. statements added
* by uses or augment), we use EffectiveSchemaContextEmitter.
*/
- new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions,
- YangVersion.parse(module.getYangVersion()).orElse(null), emitInstantiated).emitModule(module);
+ new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions, module.getYangVersion(), emitInstantiated)
+ .emitModule(module);
}
}
} else if (child instanceof ConfigStatement) {
emitConfigNode((ConfigStatement) child);
} else if (child instanceof UnknownStatement) {
- emitUnknownStatementNode((UnknownStatement<?>) child);
+ emitUnknownStatementNode(child);
}
}
super.writer.endNode();
}
}
- private void emitYangVersionNode(final String input) {
- super.writer.startYangVersionNode(input);
+ private void emitYangVersionNode(final YangVersion input) {
+ super.writer.startYangVersionNode(input.toString());
super.writer.endNode();
}
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
prefixToNs);
final YangModuleWriter yangSchemaWriter = SchemaToStatementWriterAdaptor.from(statementWriter);
final Map<QName, StatementDefinition> extensions = ExtensionStatement.mapFrom(ctx.getExtensions());
- new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions,
- YangVersion.parse(module.getYangVersion()).orElse(null), emitInstantiated).emitModule(module);
+ new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions, module.getYangVersion(), emitInstantiated)
+ .emitModule(module);
}
private static Map<String, URI> prefixToNamespace(final SchemaContext ctx, final Module module) {
* If it is an yang 1 module, check imports: If module is imported twice with different
* revisions then throw exception
*/
- if (YangVersion.VERSION_1.toString().equals(module.getYangVersion())) {
+ if (module.getYangVersion() == YangVersion.VERSION_1) {
final Date impRevision = imported.get(toName);
if (impRevision != null && !impRevision.equals(toRevision)
&& !DEFAULT_DATE_REV.equals(impRevision) && !DEFAULT_DATE_REV.equals(toRevision)) {
}
@Override
- public String getYangVersion() {
- return yangVersion.toString();
+ public YangVersion getYangVersion() {
+ return yangVersion;
}
@Override
assertNotNull(rootModule);
assertEquals("root-pref", rootModule.getPrefix());
- assertEquals(YangVersion.VERSION_1.toString(), rootModule.getYangVersion());
+ assertEquals(YangVersion.VERSION_1, rootModule.getYangVersion());
assertEquals("cisco", rootModule.getOrganization());
assertEquals("cisco email", rootModule.getContact());
@Test
public void testHeaders() throws ParseException {
assertEquals("foo", foo.getName());
- assertEquals(YangVersion.VERSION_1.toString(), foo.getYangVersion());
+ assertEquals(YangVersion.VERSION_1, foo.getYangVersion());
assertEquals(FOO.getNamespace(), foo.getNamespace());
assertEquals("foo", foo.getPrefix());
public void testYinFileHeader() throws URISyntaxException {
Module testModule = TestUtils.findModule(modules, "config").get();
- assertEquals(YangVersion.VERSION_1.toString(), testModule.getYangVersion());
+ assertEquals(YangVersion.VERSION_1, testModule.getYangVersion());
assertEquals(new URI("urn:opendaylight:params:xml:ns:yang:controller:config"), testModule.getNamespace());
assertEquals("config", testModule.getPrefix());
}