Java Code Examples for org.opendaylight.yangtools.yang.common.QName#equals()

The following examples show how to use org.opendaylight.yangtools.yang.common.QName#equals() . 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: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns RPC Input or Output Data container from RPC definition.
 *
 * @param schema SchemaContext in which lookup should be performed.
 * @param path Schema path of RPC input/output data container
 * @return Notification schema or null, if notification is not present in schema context.
 */
@Beta
public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema,
        final @NonNull SchemaPath path) {
    requireNonNull(schema, "Schema context must not be null.");
    requireNonNull(path, "Schema path must not be null.");
    final Iterator<QName> it = path.getPathFromRoot().iterator();
    checkArgument(it.hasNext(), "Rpc must have QName.");
    final QName rpcName = it.next();
    checkArgument(it.hasNext(), "input or output must be part of path.");
    final QName inOrOut = it.next();
    for (final RpcDefinition potential : schema.getOperations()) {
        if (rpcName.equals(potential.getQName())) {
            return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut);
        }
    }
    return null;
}
 
Example 2
Source File: SchemaContext.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
default Optional<NotificationDefinition> findNotification(final QName qname) {
    final Optional<Collection<? extends NotificationDefinition>> defs = findModule(qname.getModule())
            .map(Module::getNotifications);
    if (defs.isPresent()) {
        for (NotificationDefinition def : defs.get()) {
            if (qname.equals(def.getQName())) {
                return Optional.of(def);
            }
        }
    }
    return Optional.empty();
}
 
Example 3
Source File: NotificationNodeContainer.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find a notification based on its QName. Default implementation searches the set returned by
 * {@link #getNotifications()}.
 *
 * @param qname Notification QName
 * @return Notification definition, if found
 * @throws NullPointerException if qname is null
 */
default Optional<NotificationDefinition> findNotification(final QName qname) {
    requireNonNull(qname);
    for (NotificationDefinition notif : getNotifications()) {
        if (qname.equals(notif.getQName())) {
            return Optional.of(notif);
        }
    }
    return Optional.empty();
}
 
Example 4
Source File: ActionNodeContainer.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find an action based on its QName. Default implementation searches the set returned by {@link #getActions()}.
 *
 * @param qname Action's QName
 * @return Action definition, if found
 * @throws NullPointerException if qname is null
 */
default Optional<ActionDefinition> findAction(final QName qname) {
    requireNonNull(qname);
    for (ActionDefinition action : getActions()) {
        if (qname.equals(action.getQName())) {
            return Optional.of(action);
        }
    }
    return Optional.empty();
}
 
Example 5
Source File: AbstractChoiceStatementSupport.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static CaseSchemaNode findCase(final QName qname,
        final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    for (final EffectiveStatement<?, ?> effectiveStatement : substatements) {
        if (effectiveStatement instanceof CaseSchemaNode) {
            final CaseSchemaNode choiceCaseNode = (CaseSchemaNode) effectiveStatement;
            if (qname.equals(choiceCaseNode.getQName())) {
                return choiceCaseNode;
            }
        }
    }

    return null;
}
 
Example 6
Source File: Bug9242Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testDeviateReplaceWithUserDefinedTypes() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9242/");
    assertNotNull(schemaContext);

    final Revision revision = Revision.of("2017-10-13");
    final Module rootModule = schemaContext.findModule("root-module", revision).get();
    final Module impModule = schemaContext.findModule("imp-module", revision).get();

    TypeDefinition<?> deviatedMyLeafType = null;
    TypeDefinition<?> deviatedMyLeaf2Type = null;

    for (final Deviation deviation : rootModule.getDeviations()) {
        final QName last = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers());
        if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf"))) {
            deviatedMyLeafType = deviation.getDeviates().iterator().next().getDeviatedType();
        }

        if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf-2"))) {
            deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
        }
    }

    assertNotNull(deviatedMyLeafType);
    assertNotNull(deviatedMyLeaf2Type);

    final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
            impModule.getQNameModule(), "my-leaf"));
    assertSame(deviatedMyLeafType, myLeaf.getType());

    final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
            impModule.getQNameModule(), "my-leaf-2"));
    assertSame(deviatedMyLeaf2Type, myLeaf2.getType());
}
 
Example 7
Source File: YangFunctionContext.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static IdentitySchemaNode findIdentitySchemaNodeInModule(final Module module, final QName identityQName) {
    for (final IdentitySchemaNode id : module.getIdentities()) {
        if (identityQName.equals(id.getQName())) {
            return id;
        }
    }

    throw new IllegalArgumentException(String.format("Identity %s does not have a corresponding"
                + " identity schema node in the module %s.", identityQName, module));
}
 
Example 8
Source File: AbstractModuleStringIdentityrefCodec.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected final QName createQName(final String prefix, final String localName) {
    final Module module = moduleForPrefix(prefix);
    checkArgument(module != null, "Failed to lookup prefix %s", prefix);

    final QName qname = QName.create(module.getQNameModule(), localName);
    for (IdentitySchemaNode identity : module.getIdentities()) {
        if (qname.equals(identity.getQName())) {
            return identity.getQName();
        }
    }

    throw new IllegalArgumentException("Failed to find identity matching " + qname);
}
 
Example 9
Source File: IdentityCodecUtil.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parse a string into a QName using specified prefix-to-QNameModule mapping function, interpreting the result
 * as an IdentitySchemaNode existing in specified SchemaContext.
 *
 * @param value string value to parse
 * @param schemaContext Parent schema context
 * @param prefixToModule prefix-to-QNameModule mapping function
 * @return Corresponding IdentitySchemaNode.
 * @throws IllegalArgumentException if the value is invalid or does not refer to an existing identity
 */
public static IdentitySchemaNode parseIdentity(final String value, final SchemaContext schemaContext,
        final Function<String, QNameModule> prefixToModule) {
    final QName qname = QNameCodecUtil.decodeQName(value, prefixToModule);
    final Optional<Module> optModule = schemaContext.findModule(qname.getModule());
    checkState(optModule.isPresent(), "Parsed QName %s refers to a non-existent module", qname);

    for (IdentitySchemaNode identity : optModule.get().getIdentities()) {
        if (qname.equals(identity.getQName())) {
            return identity;
        }
    }

    throw new IllegalArgumentException("Parsed QName " + qname + " does not refer to a valid identity");
}
 
Example 10
Source File: AbstractMagnesiumDataOutput.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private boolean matchesParentQName(final QName qname) {
    final Object current = stack.peek();
    return current instanceof NodeIdentifier && qname.equals(((NodeIdentifier) current).getNodeType());
}