org.opendaylight.yangtools.yang.common.QName Java Examples

The following examples show how to use org.opendaylight.yangtools.yang.common.QName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StmtContextUtils.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parse a YANG node identifier string in context of a statement.
 *
 * @param ctx Statement context
 * @param str String to be parsed
 * @return An interned QName
 * @throws NullPointerException if any of the arguments are null
 * @throws SourceException if the string is not a valid YANG node identifier
 */
public static QName parseNodeIdentifier(final StmtContext<?, ?, ?> ctx, final String str) {
    SourceException.throwIf(str.isEmpty(), ctx.getStatementSourceReference(),
            "Node identifier may not be an empty string");

    final int colon = str.indexOf(':');
    if (colon == -1) {
        return internedQName(ctx, str);
    }

    final String prefix = str.substring(0, colon);
    SourceException.throwIf(prefix.isEmpty(), ctx.getStatementSourceReference(),
        "String '%s' has an empty prefix", str);
    final String localName = str.substring(colon + 1);
    SourceException.throwIf(localName.isEmpty(), ctx.getStatementSourceReference(),
        "String '%s' has an empty identifier", str);

    return parseNodeIdentifier(ctx, prefix, localName);
}
 
Example #2
Source File: YinXMLEventReader.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private void addStatement(final DeclaredStatement<?> statement) {
    final StatementDefinition def = statement.statementDefinition();
    final QName name = def.getStatementName();
    final Optional<ArgumentDefinition> optArgDef = def.getArgumentDefinition();
    if (optArgDef.isPresent()) {
        final ArgumentDefinition argDef = optArgDef.get();
        final QName argName = argDef.getArgumentName();
        if (argDef.isYinElement()) {
            events.addAll(Arrays.asList(startElement(name), startElement(argName),
                eventFactory.createCharacters(statement.rawArgument()), endElement(argName)));
        } else {
            final Entry<String, String> ns = namespaceContext.prefixAndNamespaceFor(name.getModule());
            events.add(eventFactory.createStartElement(ns.getKey(), ns.getValue(), name.getLocalName(),
                singletonIterator(attribute(argName, statement.rawArgument())), emptyIterator(), namespaceContext));
        }
    } else {
        // No attributes: just emit a start
        events.add(startElement(name));
    }

    stack.push(new OpenElement(name, statement.declaredSubstatements().iterator()));
}
 
Example #3
Source File: AbstractMagnesiumDataOutput.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private void encodeQName(final @NonNull QName qname) throws IOException {
    final Integer prev = qnameCodeMap.put(qname, qnameCodeMap.size());
    if (prev != null) {
        throw new IOException("Internal coding error: attempted to re-encode " + qname + "%s already encoded as "
                + prev);
    }

    final QNameModule module = qname.getModule();
    final Integer code = moduleCodeMap.get(module);
    if (code == null) {
        moduleCodeMap.put(module, moduleCodeMap.size());
        encodeString(module.getNamespace().toString());
        final Optional<Revision> rev = module.getRevision();
        if (rev.isPresent()) {
            encodeString(rev.get().toString());
        } else {
            output.writeByte(MagnesiumValue.STRING_EMPTY);
        }
    } else {
        writeModuleRef(code);
    }
    encodeString(qname.getLocalName());
}
 
Example #4
Source File: TableContext.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
void createTable(final DOMDataTreeWriteTransaction tx) {
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> tb =
            ImmutableNodes.mapEntryBuilder();
    tb.withNodeIdentifier((NodeIdentifierWithPredicates) this.tableId.getLastPathArgument());
    tb.withChild(EMPTY_TABLE_ATTRIBUTES);

    // tableId is keyed, but that fact is not directly visible from YangInstanceIdentifier, see BUG-2796
    final NodeIdentifierWithPredicates tableKey =
            (NodeIdentifierWithPredicates) this.tableId.getLastPathArgument();
    for (final Map.Entry<QName, Object> e : tableKey.entrySet()) {
        tb.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue()));
    }

    tx.put(LogicalDatastoreType.OPERATIONAL, this.tableId,
            tb.withChild(ImmutableChoiceNodeBuilder.create().withNodeIdentifier(
                    new NodeIdentifier(TablesUtil.BMP_ROUTES_QNAME)).build()).build());
}
 
Example #5
Source File: UnrecognizedStatementSupport.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Optional<StatementSupport<?, ?, ?>> getUnknownStatementDefinitionOf(
        final StatementDefinition yangStmtDef) {
    final QName baseQName = getStatementName();
    final QName statementName = QName.create(baseQName, yangStmtDef.getStatementName().getLocalName());

    final ModelDefinedStatementDefinition def;
    final Optional<ArgumentDefinition> optArgDef = yangStmtDef.getArgumentDefinition();
    if (optArgDef.isPresent()) {
        final ArgumentDefinition argDef = optArgDef.get();
        def = new ModelDefinedStatementDefinition(statementName, argDef.getArgumentName(), argDef.isYinElement());
    } else {
        def = new ModelDefinedStatementDefinition(statementName);
    }
    return Optional.of(new ModelDefinedStatementSupport(def));
}
 
Example #6
Source File: ImmutableMapEntryNodeBuilder.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public MapEntryNode build() {
    for (final Entry<QName, Object> key : getNodeIdentifier().entrySet()) {
        final DataContainerChild<?, ?> childNode = getChild(childrenQNamesToPaths.get(key.getKey()));

        // We have enough information to fill-in missing leaf nodes, so let's do that
        if (childNode == null) {
            LeafNode<Object> leaf = ImmutableNodes.leafNode(key.getKey(), key.getValue());
            LOG.debug("Adding leaf {} implied by key {}", leaf, key);
            withChild(leaf);
        } else {
            DataValidationException.checkListKey(getNodeIdentifier(), key.getKey(), key.getValue(),
                childNode.getValue());
        }
    }

    return new ImmutableMapEntryNode(getNodeIdentifier(), buildValue());
}
 
Example #7
Source File: JaxenTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private YangInstanceIdentifier createYangInstanceIdentifier(final boolean withPredicates) {
    YangInstanceIdentifier testYangInstanceIdentifier = YangInstanceIdentifier.of(containerAQName).node(
            containerBQName).node(leafDQName);
    if (withPredicates) {
        final Map<QName, Object> keys1 = new HashMap<>();
        keys1.put(leafAQName, "bar");

        final NodeIdentifierWithPredicates mapEntryPath1 = NodeIdentifierWithPredicates.of(listAQName , keys1);

        final Map<QName, Object> keys2 = new HashMap<>();
        keys2.put(leafBQName, "two");

        final NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(listBQName , keys2);

        testYangInstanceIdentifier = YangInstanceIdentifier.of(listAQName).node(mapEntryPath1)
                .node(listBQName).node(mapEntryPath2).node(leafBQName);
    }
    return testYangInstanceIdentifier;
}
 
Example #8
Source File: LeafRefContextTreeBuilderTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void leafRefContextUtilsTest3() {
    final QName q16 = QName.create(tst, "con1");
    final DataSchemaNode con1 = tstMod.findDataChildByName(q16).get();
    final List<LeafRefContext> allLeafRefChilds = LeafRefContextUtils.findAllLeafRefChilds(con1,
        rootLeafRefContext);

    assertNotNull(allLeafRefChilds);
    assertFalse(allLeafRefChilds.isEmpty());
    assertEquals(4, allLeafRefChilds.size());

    final QName q17 = QName.create(tst, "odl-contributor");
    final DataSchemaNode odlContributorNode = tstMod.findDataChildByName(q17).get();
    List<LeafRefContext> allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef(
            odlContributorNode, rootLeafRefContext);

    assertNotNull(allChildsReferencedByLeafRef);
    assertFalse(allChildsReferencedByLeafRef.isEmpty());
    assertEquals(1, allChildsReferencedByLeafRef.size());

    allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef(con1, rootLeafRefContext);

    assertNotNull(allChildsReferencedByLeafRef);
    assertTrue(allChildsReferencedByLeafRef.isEmpty());
}
 
Example #9
Source File: TypedefStatementSupport.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected TypedefEffectiveStatement createEffective(
        final StmtContext<QName, TypedefStatement, TypedefEffectiveStatement> ctx,
        final TypedefStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    final TypeEffectiveStatement<?> typeEffectiveStmt = findFirstStatement(substatements,
        TypeEffectiveStatement.class);
    final String dflt = findFirstArgument(substatements, DefaultEffectiveStatement.class, null);
    SourceException.throwIf(
        EffectiveStmtUtils.hasDefaultValueMarkedWithIfFeature(ctx.getRootVersion(), typeEffectiveStmt, dflt),
        ctx.getStatementSourceReference(),
        "Typedef '%s' has default value '%s' marked with an if-feature statement.", ctx.getStatementArgument(),
        dflt);

    return new TypedefEffectiveStatementImpl(declared, ctx.getSchemaPath().get(), computeFlags(substatements),
        substatements);
}
 
Example #10
Source File: EffectiveStatementTypeTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testString() {
    currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-string"));
    assertNotNull(currentLeaf.getType());
    final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement<?>)
            ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
            .getTypeDefinition();

    assertEquals("string", stringEff.getQName().getLocalName());
    assertEquals(Status.CURRENT, stringEff.getStatus());
    assertEquals(Optional.empty(), stringEff.getUnits());
    assertEquals(Optional.empty(), stringEff.getDefaultValue());
    assertNotNull(stringEff.getUnknownSchemaNodes());
    assertNull(stringEff.getBaseType());
    assertFalse(stringEff.getDescription().isPresent());
    assertFalse(stringEff.getReference().isPresent());
    assertNotNull(stringEff.toString());
    assertNotNull(stringEff.hashCode());
    assertFalse(stringEff.equals(null));
    assertFalse(stringEff.equals("test"));
    assertTrue(stringEff.equals(stringEff));
    assertEquals("string", stringEff.getPath().getLastComponent().getLocalName());
    assertFalse(stringEff.getLengthConstraint().isPresent());
    assertNotNull(stringEff.getPatternConstraints());
}
 
Example #11
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkContentFullTest(final SchemaContext context) {
    URI yangTypesNS = URI.create("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));

    checkNetconfMonitoringModuleFullTest(context, rev20130715, dateTimeTypeDef20130715);
    checkInterfacesModuleFullTest(context, rev20100924, dateTimeTypeDef20100924);
}
 
Example #12
Source File: AbstractDataObjectBuilder.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String addModel(EnumTypeDefinition enumType) {
    QName qName = enumType.getQName();
    
    //inline enumerations are a special case that needs extra enumeration
    if(qName.getLocalName().equals("enumeration") && enumType.getBaseType() == null) {
    	qName = QName.create(qName, enumType.getPath().getParent().getLastComponent().getLocalName() + "-" + qName.getLocalName());
    }

    if(! generatedEnums.containsKey(qName)) {
        log.debug("generating enum model for {}",  qName);
        String name = getName(qName);
        ModelImpl enumModel = build(enumType, qName);
        swagger.addDefinition(name, enumModel);
        generatedEnums.put(qName, DEF_PREFIX + name);
    } else {
        log.debug("reusing enum model for {}", enumType.getQName());
    }
    return generatedEnums.get(qName);
}
 
Example #13
Source File: SchemaUtils.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean belongsToCaseAugment(final CaseSchemaNode caseNode,
        final AugmentationIdentifier childToProcess) {
    for (final AugmentationSchemaNode augmentationSchema : caseNode.getAvailableAugmentations()) {

        final Set<QName> currentAugmentChildNodes = new HashSet<>();
        for (final DataSchemaNode dataSchemaNode : augmentationSchema.getChildNodes()) {
            currentAugmentChildNodes.add(dataSchemaNode.getQName());
        }

        if (childToProcess.getPossibleChildNames().equals(currentAugmentChildNodes)) {
            return true;
        }
    }

    return false;
}
 
Example #14
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkNetconfMonitoringModuleSimpleTest(final SchemaContext context,
        final Revision rev20130715, final QName dateTimeTypeDef20130715) {
    URI monitoringNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring");
    final QNameModule monitoring19700101 = QNameModule.create(monitoringNS);
    QName lockedTime = QName.create(monitoring19700101, "locked-time");

    Module monitoringModule19700101 = context.findModule("ietf-netconf-monitoring").get();
    DataSchemaNode leafLockedTime = monitoringModule19700101.getDataChildByName(lockedTime);
    assertNotNull(leafLockedTime);

    assertTrue(leafLockedTime instanceof LeafSchemaNode);
    QName lockedTimeTypeQName = ((LeafSchemaNode) leafLockedTime).getType().getQName();
    assertEquals(dateTimeTypeDef20130715, lockedTimeTypeQName);

    Collection<? extends ModuleImport> imports = monitoringModule19700101.getImports();
    assertEquals(1, imports.size());
    ModuleImport monitoringImport = imports.iterator().next();
    assertEquals("ietf-yang-types", monitoringImport.getModuleName());
    assertEquals(Optional.of(rev20130715), monitoringImport.getRevision());
}
 
Example #15
Source File: GroupingHierarchyHandler.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
private Map<QName, HierarchyNode> buildHierarchy() {
    Map<QName, HierarchyNode> result = ctx.getGroupings().stream().map(g -> new Tuple<>(g.getPath().getLastComponent(), new HierarchyNode(g.getPath())))
            .collect(Collectors.toMap(Tuple::first, Tuple::second));

    ctx.getGroupings().forEach(g -> {
        HierarchyNode node = result.get(g.getPath().getLastComponent());
        g.getUses().forEach(u -> {
            HierarchyNode parent = result.get(u.getGroupingPath().getLastComponent());
            if (parent == null) {
                log.warn("Hierarchy creation problem. No grouping with name {} found. Ignoring hierarchy relation.", u.getGroupingPath().getLastComponent());
            } else {
                node.addParent(parent);
            }

        });
    });
    return result;
}
 
Example #16
Source File: JaxenTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private void initQNames() {
    this.moduleQName = QNameModule.create(URI.create("urn:opendaylight.test2"), Revision.of("2015-08-08"));
    this.rootQName = QName.create(moduleQName, "root");
    this.listAQName = QName.create(moduleQName, "list-a");
    this.listBQName = QName.create(moduleQName, "list-b");
    this.leafAQName = QName.create(moduleQName, "leaf-a");
    this.leafBQName = QName.create(moduleQName, "leaf-b");
    this.leafDQName = QName.create(moduleQName, "leaf-d");
    this.containerAQName = QName.create(moduleQName, "container-a");
    this.containerBQName = QName.create(moduleQName, "container-b");
}
 
Example #17
Source File: IfFeatureExpr.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean test(final Set<QName> supportedFeatures) {
    for (IfFeatureExpr expr : array) {
        if (!expr.test(supportedFeatures)) {
            return false;
        }
    }
    return true;
}
 
Example #18
Source File: StmtTestUtils.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public static EffectiveModelContext parseYangSource(final String yangSourcePath,
        final StatementParserMode statementParserMode, final Set<QName> supportedFeatures)
                throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
    final URL source = StmtTestUtils.class.getResource(yangSourcePath);
    final File sourceFile = new File(source.toURI());
    return parseYangSources(statementParserMode, supportedFeatures, sourceFile);
}
 
Example #19
Source File: NormalizedDataBuilderTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static AugmentationSchemaNode getAugmentationSchemaForChild(final ContainerSchemaNode containerNode,
        final QName qname) {
    for (AugmentationSchemaNode augmentationSchema : containerNode.getAvailableAugmentations()) {
        if (augmentationSchema.findDataChildByName(qname).isPresent()) {
            return augmentationSchema;
        }
    }
    throw new IllegalStateException("Unable to find child augmentation in " + containerNode);
}
 
Example #20
Source File: AbstractListEffectiveStatement.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
AbstractListEffectiveStatement(final ListStatement declared, final SchemaPath path, final int flags,
        final StmtContext<?, ?, ?> ctx, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
        final ImmutableList<QName> keyDefinition) {
    super(declared, ctx, substatements);

    EffectiveStmtUtils.checkUniqueGroupings(ctx, substatements);
    EffectiveStmtUtils.checkUniqueTypedefs(ctx, substatements);
    EffectiveStmtUtils.checkUniqueUses(ctx, substatements);

    this.substatements = maskList(substatements);
    this.path = requireNonNull(path);
    this.keyDefinition = maskList(keyDefinition);
    this.flags = flags;
}
 
Example #21
Source File: TestingNormalizedNodeStructuresCreator.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static AugmentationNode lf12_1Node() {
    return Builders.augmentationBuilder()
            .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
                QName.create(COMPLEX_JSON, "lf12_1"),
                QName.create(COMPLEX_JSON, "lf12_2"))))
            .withChild(Builders.leafBuilder()
                .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf12_1")))
                .withValue("lf12 value").build())
            .build();
}
 
Example #22
Source File: EffectiveStatementTypeTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testDecimal64() {
    currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-decimal64"));
    assertNotNull(currentLeaf.getType());
    final DecimalTypeDefinition decimal64Eff = (DecimalTypeDefinition) ((TypeDefinitionAware)
            ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
            .getTypeDefinition();

    assertNull(decimal64Eff.getBaseType());
    assertEquals(Optional.empty(), decimal64Eff.getUnits());
    assertEquals(Optional.empty(), decimal64Eff.getDefaultValue());
    assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
    assertNotNull(decimal64Eff.getUnknownSchemaNodes());

    // FIXME: The yang model api is wrong: description/reference/status are not allowed under 'type', how come we
    // parse it?
    // allowed under 'type', how come we parse it?
    assertFalse(decimal64Eff.getDescription().isPresent());
    assertFalse(decimal64Eff.getReference().isPresent());
    assertEquals(Status.CURRENT, decimal64Eff.getStatus());

    assertEquals(3, decimal64Eff.getRangeConstraint().get().getAllowedRanges().asRanges().size());
    assertNotNull(decimal64Eff.toString());
    assertNotNull(decimal64Eff.hashCode());
    assertEquals(2, decimal64Eff.getFractionDigits());
    assertFalse(decimal64Eff.equals(null));
    assertFalse(decimal64Eff.equals("test"));
    assertTrue(decimal64Eff.equals(decimal64Eff));
    assertEquals("decimal64", decimal64Eff.getPath().getLastComponent().getLocalName());
}
 
Example #23
Source File: Bug4295Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void init() {
    foo = QNameModule.create(URI.create("foo"));
    root = QName.create(foo, "root");
    subRoot = QName.create(foo, "sub-root");
    outerList = QName.create(foo, "outer-list");
    innerList = QName.create(foo, "inner-list");
    oid = QName.create(foo, "o-id");
    iid = QName.create(foo, "i-id");
    oleaf = QName.create(foo, "o");
    ileaf = QName.create(foo, "i");
    inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
        YangParserTestUtils.parseYangResource("/bug-4295/foo.yang"));
}
 
Example #24
Source File: NormalizedNodeWriterTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() {
    bazModule = QNameModule.create(URI.create("baz-namespace"), Revision.of("1970-01-01"));
    myKeyedList = QName.create(bazModule, "my-keyed-list");
    myKeyLeaf = QName.create(bazModule, "my-key-leaf");
    myLeafList = QName.create(bazModule, "my-leaf-list");
}
 
Example #25
Source File: AbstractListStatementSupport.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void warnConfigList(final @NonNull StmtContext<QName, ListStatement, ListEffectiveStatement> ctx) {
    final StmtContext<QName, ListStatement, ListEffectiveStatement> warnCtx = ctx.getOriginalCtx().orElse(ctx);
    final Boolean warned = warnCtx.getFromNamespace(ConfigListWarningNamespace.class, Boolean.TRUE);
    // Hacky check if we have issued a warning for the original statement
    if (warned == null) {
        verify(warnCtx instanceof Mutable, "Unexpected context %s", warnCtx);
        ((Mutable<?, ?, ?>) warnCtx).addToNs(ConfigListWarningNamespace.class, Boolean.TRUE, Boolean.TRUE);
        LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
                + "this is fine with OpenDaylight, it can cause interoperability issues with other systems "
                + "[defined at {}]", ctx.getStatementArgument(), warnCtx.getStatementSourceReference());
    }
}
 
Example #26
Source File: ActionStatementSupport.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onFullDefinitionDeclared(final Mutable<QName, ActionStatement, ActionEffectiveStatement> stmt) {
    super.onFullDefinitionDeclared(stmt);

    if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, InputStatement.class) == null) {
        ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(
            InputStatementRFC7950Support.getInstance(), null);
    }
    if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, OutputStatement.class) == null) {
        ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(
            OutputStatementRFC7950Support.getInstance(), null);
    }
}
 
Example #27
Source File: AbstractInputStatementSupport.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected final InputStatement createEmptyDeclared(final StmtContext<QName, InputStatement, ?> ctx) {
    final StatementSource source = ctx.getStatementSource();
    switch (ctx.getStatementSource()) {
        case CONTEXT:
            return new EmptyUndeclaredInputStatement(ctx.coerceStatementArgument());
        case DECLARATION:
            return new EmptyInputStatement(ctx.coerceStatementArgument());
        default:
            throw new IllegalStateException("Unhandled statement source " + source);
    }
}
 
Example #28
Source File: StmtTestUtils.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public static EffectiveModelContext parseYangSources(final String yangFilesDirectoryPath,
        final String yangLibsDirectoryPath, final Set<QName> supportedFeatures) throws URISyntaxException,
        ReactorException, IOException, YangSyntaxErrorException {
    final File yangsDir = new File(StmtTestUtils.class.getResource(yangFilesDirectoryPath).toURI());
    final File libsDir = new File(StmtTestUtils.class.getResource(yangLibsDirectoryPath).toURI());

    return parseYangSources(yangsDir.listFiles(YANG_FILE_FILTER), libsDir.listFiles(YANG_FILE_FILTER),
            supportedFeatures);
}
 
Example #29
Source File: NormalizedNodesTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testToStringTree() {
    final LeafNode<?> mockedLeafNode = mock(LeafNode.class);
    final QName leafNodeQName = QName.create("test-ns", "2016-09-16", "leaf-node");
    final NodeIdentifier leafNodeId = new NodeIdentifier(leafNodeQName);
    doReturn(leafNodeId).when(mockedLeafNode).getIdentifier();
    doReturn("str-value-1").when(mockedLeafNode).getValue();

    String stringTree = NormalizedNodes.toStringTree(mockedLeafNode);
    assertNotNull(stringTree);
    assertEquals("leaf-node str-value-1\n", stringTree);

    final AugmentationNode mockedAugmentationNode = mock(AugmentationNode.class);
    final QName listQName = QName.create("test-ns", "2016-09-16", "list-node");
    final AugmentationIdentifier augNodeId = new AugmentationIdentifier(ImmutableSet.of(listQName));
    doReturn(augNodeId).when(mockedAugmentationNode).getIdentifier();

    final MapNode mockedMapNode = mock(MapNode.class);
    final NodeIdentifier listNodeId = new NodeIdentifier(listQName);
    doReturn(listNodeId).when(mockedMapNode).getIdentifier();
    doReturn(Collections.singletonList(mockedMapNode)).when(mockedAugmentationNode).getValue();

    final MapEntryNode mockedMapEntryNode = mock(MapEntryNode.class);
    final NodeIdentifierWithPredicates listEntryNodeId = NodeIdentifierWithPredicates.of(listQName,
            leafNodeQName, "key-leaf-value");
    doReturn(listEntryNodeId).when(mockedMapEntryNode).getIdentifier();
    doReturn(Collections.singletonList(mockedMapEntryNode)).when(mockedMapNode).getValue();

    doReturn(Collections.singletonList(mockedLeafNode)).when(mockedMapEntryNode).getValue();

    stringTree = NormalizedNodes.toStringTree(mockedAugmentationNode);
    assertNotNull(stringTree);
    assertEquals("augmentation {\n    list-node {\n        list-node[key-leaf-value] {\n            leaf-node "
            + "str-value-1\n        }\n    }\n}\n", stringTree);
}
 
Example #30
Source File: ActionEffectiveStatementImpl.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
ActionEffectiveStatementImpl(final ActionStatement declared, final SchemaPath path, final int flags,
        final StmtContext<QName, ActionStatement, ActionEffectiveStatement> ctx,
        final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    super(declared, ctx, substatements);
    this.path = requireNonNull(path);
    this.flags = flags;
}