Search in sources :

Example 21 with XMLNamespace

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;
}
Also used : QNameToStatementDefinition(org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition) StatementDefinition(org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace)

Example 22 with XMLNamespace

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());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Deviation(org.opendaylight.yangtools.yang.model.api.Deviation) Test(org.junit.Test)

Example 23 with XMLNamespace

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);
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) QName(org.opendaylight.yangtools.yang.common.QName) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 24 with XMLNamespace

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());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) ModuleImport(org.opendaylight.yangtools.yang.model.api.ModuleImport) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 25 with XMLNamespace

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;
}
Also used : TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) HashSet(java.util.HashSet)

Aggregations

XMLNamespace (org.opendaylight.yangtools.yang.common.XMLNamespace)35 Module (org.opendaylight.yangtools.yang.model.api.Module)14 QName (org.opendaylight.yangtools.yang.common.QName)12 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)9 Revision (org.opendaylight.yangtools.yang.common.Revision)9 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)9 Test (org.junit.Test)8 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)4 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)3 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)3 ModuleImport (org.opendaylight.yangtools.yang.model.api.ModuleImport)3 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 Optional (java.util.Optional)2