use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project controller by opendaylight.
the class RuntimeRegistratorTest method prepareRootRB.
// TODO add more tests
protected RuntimeBeanEntry prepareRootRB(final List<RuntimeBeanEntry> children) {
final DataNodeContainer nodeContainer = mock(DataNodeContainer.class);
doReturn("DataSchemaNode").when(nodeContainer).toString();
return new RuntimeBeanEntry("pa.cka.ge", nodeContainer, "module-name", "ModuleName", true, Optional.absent(), Collections.emptyList(), children, Collections.emptySet());
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.
the class InMemoryDataTree method internalSetSchemaContext.
/*
* This method is synchronized to guard against user attempting to install
* multiple contexts. Otherwise it runs in a lock-free manner.
*/
private synchronized void internalSetSchemaContext(final EffectiveModelContext newSchemaContext) {
requireNonNull(newSchemaContext);
LOG.debug("Following schema contexts will be attempted {}", newSchemaContext);
final DataSchemaContextTree contextTree = DataSchemaContextTree.from(newSchemaContext);
final Optional<DataSchemaContextNode<?>> rootContextNode = contextTree.findChild(getRootPath());
if (!rootContextNode.isPresent()) {
LOG.warn("Could not find root {} in new schema context, not upgrading", getRootPath());
return;
}
final DataSchemaNode rootSchemaNode = rootContextNode.get().getDataSchemaNode();
if (!(rootSchemaNode instanceof DataNodeContainer)) {
LOG.warn("Root {} resolves to non-container type {}, not upgrading", getRootPath(), rootSchemaNode);
return;
}
final ModificationApplyOperation rootNode = getOperation(rootSchemaNode);
DataTreeState currentState;
DataTreeState newState;
do {
currentState = currentState();
newState = currentState.withSchemaContext(newSchemaContext, rootNode);
// TODO: can we lower this to compareAndSwapRelease?
} while (!STATE.compareAndSet(this, currentState, newState));
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.
the class UniqueValidation method toDescendantPath.
private static ImmutableList<NodeIdentifier> toDescendantPath(final ListSchemaNode parent, final Descendant descendant) {
final List<QName> qnames = descendant.getNodeIdentifiers();
final ImmutableList.Builder<NodeIdentifier> builder = ImmutableList.builderWithExpectedSize(qnames.size());
final Iterator<QName> it = descendant.getNodeIdentifiers().iterator();
DataNodeContainer current = parent;
while (true) {
final QName qname = it.next();
final DataSchemaNode next = current.findDataChildByName(qname).orElseThrow(() -> new IllegalStateException("Cannot find component " + qname + " of " + descendant));
builder.add(NodeIdentifier.create(qname));
if (!it.hasNext()) {
checkState(next instanceof TypedDataSchemaNode, "Unexpected schema %s for %s", next, descendant);
final ImmutableList<NodeIdentifier> ret = builder.build();
LOG.trace("Resolved {} to {}", descendant, ret);
return ret;
}
checkState(next instanceof DataNodeContainer, "Unexpected non-container %s for %s", next, descendant);
current = (DataNodeContainer) next;
}
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.
the class LeafRefContextTreeBuilder method buildLeafRefContextReferencingTree.
private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final SchemaInferenceStack stack) {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(), stack.toSchemaPath(), schemaContext);
if (node instanceof DataNodeContainer) {
for (final DataSchemaNode childNode : ((DataNodeContainer) node).getChildNodes()) {
stack.enterSchemaTree(childNode.getQName());
final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(childNode, stack);
stack.exit();
if (childLeafRefContext.hasReferencingChild() || childLeafRefContext.isReferencing()) {
currentLeafRefContextBuilder.addReferencingChild(childLeafRefContext, childLeafRefContext.getNodeName());
}
}
} else if (node instanceof ChoiceSchemaNode) {
// :FIXME choice without case
for (final CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
stack.enterSchemaTree(caseNode.getQName());
final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(caseNode, stack);
stack.exit();
if (childLeafRefContext.hasReferencingChild() || childLeafRefContext.isReferencing()) {
currentLeafRefContextBuilder.addReferencingChild(childLeafRefContext, childLeafRefContext.getNodeName());
}
}
} else if (node instanceof TypedDataSchemaNode) {
final TypedDataSchemaNode typedNode = (TypedDataSchemaNode) node;
final TypeDefinition<?> type = typedNode.getType();
// FIXME: fix case when type is e.g. typedef -> typedef -> leafref
if (type instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafrefType = (LeafrefTypeDefinition) type;
final PathExpression path = leafrefType.getPathStatement();
final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(leafrefType, typedNode);
final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPath(path);
currentLeafRefContextBuilder.setLeafRefTargetPathString(path.getOriginalString());
currentLeafRefContextBuilder.setReferencing(true);
currentLeafRefContextBuilder.setLeafRefTargetPath(leafRefPath);
final LeafRefContext currentLeafRefContext = currentLeafRefContextBuilder.build();
leafRefs.add(currentLeafRefContext);
return currentLeafRefContext;
}
}
return currentLeafRefContextBuilder.build();
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.
the class LeafRefContextTreeBuilder method buildLeafRefContextReferencedByTree.
private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule, final SchemaInferenceStack stack) {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(), stack.toSchemaPath(), schemaContext);
if (node instanceof DataNodeContainer) {
for (final DataSchemaNode childNode : ((DataNodeContainer) node).getChildNodes()) {
stack.enterSchemaTree(childNode.getQName());
final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(childNode, currentModule, stack);
stack.exit();
if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
currentLeafRefContextBuilder.addReferencedByChild(childLeafRefContext, childLeafRefContext.getNodeName());
}
}
} else if (node instanceof ChoiceSchemaNode) {
for (final CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
stack.enterSchemaTree(caseNode.getQName());
final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(caseNode, currentModule, stack);
stack.exit();
if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
currentLeafRefContextBuilder.addReferencedByChild(childLeafRefContext, childLeafRefContext.getNodeName());
}
}
} else if (node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode) {
final List<LeafRefContext> foundLeafRefs = getLeafRefsFor(currentModule, stack);
if (!foundLeafRefs.isEmpty()) {
currentLeafRefContextBuilder.setReferencedBy(true);
for (final LeafRefContext leafRef : foundLeafRefs) {
currentLeafRefContextBuilder.addReferencedByLeafRefCtx(leafRef.getNodeName(), leafRef);
}
}
}
return currentLeafRefContextBuilder.build();
}
Aggregations