use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project yangtools by opendaylight.
the class AnydataNormalizeToContainerTest method testAnydataNormalizeToContainer.
@Test
public void testAnydataNormalizeToContainer() throws Exception {
// Create Data Scheme from yang file
final SchemaNode fooSchemaNode = SCHEMA_CONTEXT.findDataTreeChild(FOO_QNAME).orElse(null);
assertThat(fooSchemaNode, instanceOf(AnydataSchemaNode.class));
final AnydataSchemaNode anyDataSchemaNode = (AnydataSchemaNode) fooSchemaNode;
final SchemaNode barSchemaNode = SCHEMA_CONTEXT.findDataTreeChild(CONT_QNAME).orElse(null);
assertThat(barSchemaNode, instanceOf(ContainerSchemaNode.class));
final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) barSchemaNode;
// deserialization
final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(toInputStream("<foo xmlns=\"test-anydata\">" + "<bar xmlns=\"test-anydata\">" + "<cont-leaf>somedata</cont-leaf>" + "</bar>" + "</foo>"));
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, Inference.ofDataTreePath(SCHEMA_CONTEXT, FOO_QNAME));
xmlParser.parse(reader);
final NormalizedNode transformedInput = result.getResult();
assertThat(transformedInput, instanceOf(AnydataNode.class));
AnydataNode<?> anydataNode = (AnydataNode<?>) transformedInput;
// Normalize anydata content to specific container element
DOMSourceAnydata domSourceAnydata = (DOMSourceAnydata) anydataNode.body();
NormalizedAnydata normalizedAnydata = domSourceAnydata.normalizeTo(DefaultSchemaTreeInference.of(SCHEMA_CONTEXT, Absolute.of(CONT_QNAME)));
assertNotNull(normalizedAnydata);
}
use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project yangtools by opendaylight.
the class CompositeNodeDataWithSchema method addSimpleChild.
private AbstractNodeDataWithSchema<?> addSimpleChild(final DataSchemaNode schema, final ChildReusePolicy policy) {
final SimpleNodeDataWithSchema<?> newChild;
if (schema instanceof LeafSchemaNode) {
newChild = new LeafNodeDataWithSchema((LeafSchemaNode) schema);
} else if (schema instanceof AnyxmlSchemaNode) {
newChild = new AnyXmlNodeDataWithSchema((AnyxmlSchemaNode) schema);
} else if (schema instanceof AnydataSchemaNode) {
newChild = new AnydataNodeDataWithSchema((AnydataSchemaNode) schema);
} else {
return null;
}
final AugmentationSchemaNode augSchema;
if (schema.isAugmenting()) {
augSchema = findCorrespondingAugment(getSchema(), schema);
} else {
augSchema = null;
}
if (augSchema != null) {
augmentationsToChild.put(augSchema, newChild);
} else {
addChild(newChild);
}
return newChild;
}
use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project mdsal by opendaylight.
the class DataContainerCodecPrototype method computeChildAddressabilitySummary.
private static ChildAddressabilitySummary computeChildAddressabilitySummary(final Object nodeSchema) {
// FIXME: rework this to work on EffectiveStatements
if (nodeSchema instanceof DataNodeContainer) {
boolean haveAddressable = false;
boolean haveUnaddressable = false;
for (DataSchemaNode child : ((DataNodeContainer) nodeSchema).getChildNodes()) {
if (child instanceof ContainerSchemaNode || child instanceof AugmentationSchemaNode) {
haveAddressable = true;
} else if (child instanceof ListSchemaNode) {
if (((ListSchemaNode) child).getKeyDefinition().isEmpty()) {
haveUnaddressable = true;
} else {
haveAddressable = true;
}
} else if (child instanceof AnydataSchemaNode || child instanceof AnyxmlSchemaNode || child instanceof TypedDataSchemaNode) {
haveUnaddressable = true;
} else if (child instanceof ChoiceSchemaNode) {
switch(computeChildAddressabilitySummary(child)) {
case ADDRESSABLE:
haveAddressable = true;
break;
case MIXED:
haveAddressable = true;
haveUnaddressable = true;
break;
case UNADDRESSABLE:
haveUnaddressable = true;
break;
default:
throw new IllegalStateException("Unhandled accessibility summary for " + child);
}
} else {
LOG.warn("Unhandled child node {}", child);
}
}
if (!haveAddressable) {
// Empty or all are unaddressable
return ChildAddressabilitySummary.UNADDRESSABLE;
}
return haveUnaddressable ? ChildAddressabilitySummary.MIXED : ChildAddressabilitySummary.ADDRESSABLE;
} else if (nodeSchema instanceof ChoiceSchemaNode) {
boolean haveAddressable = false;
boolean haveUnaddressable = false;
for (CaseSchemaNode child : ((ChoiceSchemaNode) nodeSchema).getCases()) {
switch(computeChildAddressabilitySummary(child)) {
case ADDRESSABLE:
haveAddressable = true;
break;
case UNADDRESSABLE:
haveUnaddressable = true;
break;
case MIXED:
// A child is mixed, which means we are mixed, too
return ChildAddressabilitySummary.MIXED;
default:
throw new IllegalStateException("Unhandled accessibility summary for " + child);
}
}
if (!haveAddressable) {
// Empty or all are unaddressable
return ChildAddressabilitySummary.UNADDRESSABLE;
}
return haveUnaddressable ? ChildAddressabilitySummary.MIXED : ChildAddressabilitySummary.ADDRESSABLE;
}
// No child nodes possible: return unaddressable
return ChildAddressabilitySummary.UNADDRESSABLE;
}
Aggregations