use of org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode in project controller by opendaylight.
the class UintAdaptingPruner method adaptEntry.
private void adaptEntry(final ReusableImmutableNormalizedNodeStreamWriter writer, final NodeWithValue<?> name) {
final NodeWithValue<?> adapted;
final DataSchemaNode schema = currentSchema().getDataSchemaNode();
if (schema instanceof TypedDataSchemaNode) {
final Object oldValue = name.getValue();
final Object newValue = adaptValue(((TypedDataSchemaNode) schema).getType(), oldValue);
adapted = newValue == oldValue ? name : new NodeWithValue<>(name.getNodeType(), newValue);
} else {
adapted = name;
}
writer.startLeafSetEntryNode(adapted);
}
use of org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode in project yangtools by opendaylight.
the class XmlStreamUtilsTest method getTargetNodeForLeafRef.
private static TypeDefinition<?> getTargetNodeForLeafRef(final Class<?> clas, final String... names) {
final SchemaInferenceStack stack = SchemaInferenceStack.of(schemaContext);
stack.enterDataTree(QName.create(leafRefModule.getQNameModule(), "cont2"));
for (String name : names) {
stack.enterDataTree(QName.create(leafRefModule.getQNameModule(), name));
}
final EffectiveStatement<?, ?> leaf = stack.currentStatement();
assertThat(leaf, instanceOf(LeafSchemaNode.class));
final TypeDefinition<? extends TypeDefinition<?>> type = ((TypedDataSchemaNode) leaf).getType();
assertThat(type, instanceOf(LeafrefTypeDefinition.class));
final TypeDefinition<?> resolved = stack.resolveLeafref((LeafrefTypeDefinition) type);
assertThat(resolved, instanceOf(clas));
return resolved;
}
use of org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode 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.TypedDataSchemaNode 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.TypedDataSchemaNode in project yangtools by opendaylight.
the class SchemaInferenceStack method resolveLeafref.
@Override
public TypeDefinition<?> resolveLeafref(final LeafrefTypeDefinition type) {
final SchemaInferenceStack tmp = copy();
LeafrefTypeDefinition current = type;
while (true) {
final EffectiveStatement<?, ?> resolved = tmp.resolvePathExpression(current.getPathStatement());
checkState(resolved instanceof TypeAware, "Unexpected result %s resultion of %s", resolved, type);
final TypeDefinition<?> result = ((TypedDataSchemaNode) resolved).getType();
if (result instanceof LeafrefTypeDefinition) {
checkArgument(result != type, "Resolution of %s loops back onto itself via %s", type, current);
current = (LeafrefTypeDefinition) result;
} else {
return result;
}
}
}
Aggregations