use of org.opendaylight.yangtools.yang.model.api.UsesNode in project controller by opendaylight.
the class RuntimeBeanEntry method getIdentitiesToRpcs.
private static Multimap<QName, /* of identity */
RpcDefinition> getIdentitiesToRpcs(final SchemaContext schemaCtx) {
Multimap<QName, RpcDefinition> result = HashMultimap.create();
for (Module currentModule : schemaCtx.getModules()) {
// Find all identities in current module for later identity->rpc mapping
Set<QName> allIdentitiesInModule = Sets.newHashSet(Collections2.transform(currentModule.getIdentities(), SchemaNode::getQName));
for (RpcDefinition rpc : currentModule.getRpcs()) {
ContainerSchemaNode input = rpc.getInput();
if (input != null) {
for (UsesNode uses : input.getUses()) {
// Check if the rpc is config rpc by looking for input argument rpc-context-ref
Iterator<QName> pathFromRoot = uses.getGroupingPath().getPathFromRoot().iterator();
if (!pathFromRoot.hasNext() || !pathFromRoot.next().equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME)) {
continue;
}
for (SchemaNode refinedNode : uses.getRefines().values()) {
for (UnknownSchemaNode unknownSchemaNode : refinedNode.getUnknownSchemaNodes()) {
if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode.getNodeParameter();
QName identityQName = QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
Preconditions.checkArgument(allIdentitiesInModule.contains(identityQName), "Identity referenced by rpc not found. Identity: %s, rpc: %s", localIdentityName, rpc);
result.put(identityQName, rpc);
}
}
}
}
}
}
}
return result;
}
use of org.opendaylight.yangtools.yang.model.api.UsesNode in project controller by opendaylight.
the class ModuleMXBeanEntryBuilder method extractDependency.
private static Optional<? extends AbstractDependencyAttribute> extractDependency(final DataNodeContainer dataNodeContainer, final DataSchemaNode attrNode, final Module currentModule, final Map<QName, ServiceInterfaceEntry> qNamesToSIEs, final SchemaContext schemaContext) {
if (isDependencyContainer(dataNodeContainer)) {
// reference
UsesNode usesNode = dataNodeContainer.getUses().iterator().next();
for (SchemaNode refineNode : usesNode.getRefines().values()) {
// this will ignore name nodes, since they are not needed here
if (TYPE.equals(refineNode.getQName().getLocalName())) {
checkState(refineNode.getUnknownSchemaNodes().size() == 1, "Unexpected unknown schema node size of " + refineNode);
UnknownSchemaNode requiredIdentity = refineNode.getUnknownSchemaNodes().iterator().next();
checkState(ConfigConstants.REQUIRED_IDENTITY_EXTENSION_QNAME.equals(requiredIdentity.getNodeType()), "Unexpected language extension " + requiredIdentity);
String prefixAndIdentityLocalName = requiredIdentity.getNodeParameter();
// import should point to a module
ServiceInterfaceEntry serviceInterfaceEntry = findSIE(prefixAndIdentityLocalName, currentModule, qNamesToSIEs, schemaContext);
LeafSchemaNode refine = (LeafSchemaNode) usesNode.getRefines().values().iterator().next();
boolean mandatory = refine.isMandatory();
AbstractDependencyAttribute reference;
if (dataNodeContainer instanceof ContainerSchemaNode) {
reference = new DependencyAttribute(attrNode, serviceInterfaceEntry, mandatory, attrNode.getDescription().orElse(null));
} else {
reference = new ListDependenciesAttribute(attrNode, serviceInterfaceEntry, mandatory, attrNode.getDescription().orElse(null));
}
return Optional.of(reference);
}
}
}
return Optional.absent();
}
use of org.opendaylight.yangtools.yang.model.api.UsesNode in project controller by opendaylight.
the class RuntimeBeanEntry method findQNameFromGrouping.
/**
* Find "proper" qname of unknown node in case it comes from a grouping
*/
private static QName findQNameFromGrouping(final DataNodeContainer subtree, final SchemaContext ctx, final UnknownSchemaNode unknownSchemaNode, final String localIdentityName) {
QName identityQName = null;
for (UsesNode usesNode : subtree.getUses()) {
SchemaNode dataChildByName = SchemaContextUtil.findDataSchemaNode(ctx, usesNode.getGroupingPath());
Module m = SchemaContextUtil.findParentModule(ctx, dataChildByName);
List<UnknownSchemaNode> unknownSchemaNodes = dataChildByName.getUnknownSchemaNodes();
if (Collections2.transform(unknownSchemaNodes, UNKNOWN_NODE_TO_STRING).contains(UNKNOWN_NODE_TO_STRING.apply(unknownSchemaNode))) {
identityQName = QName.create(dataChildByName.getQName(), localIdentityName);
}
}
return identityQName;
}
Aggregations