Search in sources :

Example 11 with AnydataSchemaNode

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);
}
Also used : AnydataNode(org.opendaylight.yangtools.yang.data.api.schema.AnydataNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) XMLStreamReader(javax.xml.stream.XMLStreamReader) NormalizedNodeResult(org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult) ImmutableNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedAnydata(org.opendaylight.yangtools.yang.data.api.schema.NormalizedAnydata) Test(org.junit.Test)

Example 12 with AnydataSchemaNode

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;
}
Also used : AugmentationSchemaNode(org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)

Example 13 with AnydataSchemaNode

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;
}
Also used : AugmentationSchemaNode(org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)

Aggregations

AnydataSchemaNode (org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode)13 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)10 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)7 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)7 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)7 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)6 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)5 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)5 Test (org.junit.Test)4 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)4 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)3 DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)3 TypedDataSchemaNode (org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1