Search in sources :

Example 21 with AnyxmlSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode 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 22 with AnyxmlSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode 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

AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)22 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)15 Test (org.junit.Test)13 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)13 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)12 AnydataSchemaNode (org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode)10 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)10 Module (org.opendaylight.yangtools.yang.model.api.Module)10 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)8 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)7 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)6 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)5 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)4 GroupingDefinition (org.opendaylight.yangtools.yang.model.api.GroupingDefinition)4 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 QName (org.opendaylight.yangtools.yang.common.QName)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2