use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class YinStatementStreamSource method getValidDefinition.
private static StatementDefinition getValidDefinition(final Node node, final StatementWriter writer, final QNameToStatementDefinition stmtDef, final StatementSourceReference ref) {
final XMLNamespace uri = NS_CACHE.getUnchecked(node.getNamespaceURI());
final StatementDefinition def = stmtDef.getByNamespaceAndLocalName(uri, node.getLocalName());
if (def == null) {
SourceException.throwIf(writer.getPhase().equals(ModelProcessingPhase.FULL_DECLARATION), ref, "%s is not a YIN statement or use of extension.", node.getLocalName());
}
return def;
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class YangParserWithContextTest method testDeviation.
@Test
public void testDeviation() throws ReactorException {
final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild().addSource(sourceForResource("/model/bar.yang")).addSource(sourceForResource("/context-test/deviation-test.yang")).buildEffective();
final Module testModule = context.findModule("deviation-test", Revision.of("2013-02-27")).get();
final Collection<? extends Deviation> deviations = testModule.getDeviations();
assertEquals(1, deviations.size());
final Deviation dev = deviations.iterator().next();
assertEquals(Optional.of("system/user ref"), dev.getReference());
final XMLNamespace expectedNS = XMLNamespace.of("urn:opendaylight.bar");
final Revision expectedRev = Revision.of("2013-07-03");
assertEquals(Absolute.of(QName.create(expectedNS, expectedRev, "interfaces"), QName.create(expectedNS, expectedRev, "ifEntry")), dev.getTargetPath());
assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType());
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class MoreRevisionsTest method checkContentSimpleTest.
private static void checkContentSimpleTest(final EffectiveModelContext context) {
final XMLNamespace yangTypesNS = XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-yang-types");
final Revision rev20100924 = Revision.of("2010-09-24");
final Revision rev20130516 = Revision.of("2013-05-16");
final Revision rev20130715 = Revision.of("2013-07-15");
final QNameModule yangTypes20100924 = QNameModule.create(yangTypesNS, rev20100924);
final QNameModule yangTypes20130516 = QNameModule.create(yangTypesNS, rev20130516);
final QNameModule yangTypes20130715 = QNameModule.create(yangTypesNS, rev20130715);
final QName dateTimeTypeDef20100924 = QName.create(yangTypes20100924, "date-and-time");
final QName dateTimeTypeDef20130516 = QName.create(yangTypes20130516, "date-and-time");
final QName dateTimeTypeDef20130715 = QName.create(yangTypes20130715, "date-and-time");
Module yangTypesModule20100924 = context.findModule("ietf-yang-types", rev20100924).get();
Module yangTypesModule20130516 = context.findModule("ietf-yang-types", rev20130516).get();
Module yangTypesModule20130715 = context.findModule("ietf-yang-types", rev20130715).get();
assertTrue(findTypeDef(yangTypesModule20100924, dateTimeTypeDef20100924));
assertTrue(findTypeDef(yangTypesModule20130516, dateTimeTypeDef20130516));
assertTrue(findTypeDef(yangTypesModule20130715, dateTimeTypeDef20130715));
checkNetconfMonitoringModuleSimpleTest(context, rev20130715, dateTimeTypeDef20130715);
checkInterfacesModuleSimpleTest(context, rev20100924, dateTimeTypeDef20100924);
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class MoreRevisionsTest method checkInterfacesModuleSimpleTest.
private static void checkInterfacesModuleSimpleTest(final EffectiveModelContext context, final Revision rev20100924, final QName dateTimeTypeDef20100924) {
XMLNamespace interfacesNS = XMLNamespace.of("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);
assertThat(leafLastChange, instanceOf(LeafSchemaNode.class));
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());
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class JsonParserStream method resolveAllPotentialNamespaces.
private Set<XMLNamespace> resolveAllPotentialNamespaces(final String elementName, final DataSchemaNode dataSchemaNode) {
final Set<XMLNamespace> potentialUris = new HashSet<>();
final Set<ChoiceSchemaNode> choices = new HashSet<>();
if (dataSchemaNode instanceof DataNodeContainer) {
for (final DataSchemaNode childSchemaNode : ((DataNodeContainer) dataSchemaNode).getChildNodes()) {
if (childSchemaNode instanceof ChoiceSchemaNode) {
choices.add((ChoiceSchemaNode) childSchemaNode);
} else if (childSchemaNode.getQName().getLocalName().equals(elementName)) {
potentialUris.add(childSchemaNode.getQName().getNamespace());
}
}
for (final ChoiceSchemaNode choiceNode : choices) {
for (final CaseSchemaNode concreteCase : choiceNode.getCases()) {
potentialUris.addAll(resolveAllPotentialNamespaces(elementName, concreteCase));
}
}
}
return potentialUris;
}
Aggregations