Search in sources :

Example 1 with DataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.DataSchemaNode in project controller by opendaylight.

the class ModuleMXBeanEntryBuilder method fillConfiguration.

private static Map<String, AttributeIfc> fillConfiguration(final DataNodeContainer dataNodeContainer, final Module currentModule, final TypeProviderWrapper typeProviderWrapper, final Map<QName, ServiceInterfaceEntry> qNamesToSIEs, final SchemaContext schemaContext, final String packageName) {
    Map<String, AttributeIfc> yangToAttributes = new HashMap<>();
    for (DataSchemaNode attrNode : dataNodeContainer.getChildNodes()) {
        AttributeIfc attributeValue = getAttributeValue(attrNode, currentModule, qNamesToSIEs, typeProviderWrapper, schemaContext, packageName);
        yangToAttributes.put(attributeValue.getAttributeYangName(), attributeValue);
    }
    return yangToAttributes;
}
Also used : HashMap(java.util.HashMap) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)

Example 2 with DataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.DataSchemaNode in project controller by opendaylight.

the class RuntimeBeanEntry method extractSubtree.

/**
 * Get direct descendants of this subtree, together with attributes defined
 * in subtree.
 */
private static AttributesRpcsAndRuntimeBeans extractSubtree(final String packageName, final DataNodeContainer subtree, final TypeProviderWrapper typeProviderWrapper, final Module currentModule, final SchemaContext ctx) {
    Multimap<QName, RpcDefinition> identitiesToRpcs = getIdentitiesToRpcs(ctx);
    List<AttributeIfc> attributes = Lists.newArrayList();
    List<RuntimeBeanEntry> runtimeBeanEntries = new ArrayList<>();
    for (DataSchemaNode child : subtree.getChildNodes()) {
        // runtime beans
        if (child instanceof LeafSchemaNode) {
            // just save the attribute
            LeafSchemaNode leaf = (LeafSchemaNode) child;
            attributes.add(new JavaAttribute(leaf, typeProviderWrapper));
        } else if (child instanceof ContainerSchemaNode) {
            ContainerSchemaNode container = (ContainerSchemaNode) child;
            // this can be either TO or hierarchical RB
            TOAttribute toAttribute = TOAttribute.create(container, typeProviderWrapper, packageName);
            attributes.add(toAttribute);
        } else if (child instanceof ListSchemaNode) {
            if (isInnerStateBean(child)) {
                ListSchemaNode listSchemaNode = (ListSchemaNode) child;
                RuntimeBeanEntry hierarchicalChild = createHierarchical(packageName, listSchemaNode, typeProviderWrapper, currentModule, ctx);
                runtimeBeanEntries.add(hierarchicalChild);
            } else /* ordinary list attribute */
            {
                ListAttribute listAttribute = ListAttribute.create((ListSchemaNode) child, typeProviderWrapper, packageName);
                attributes.add(listAttribute);
            }
        } else if (child instanceof LeafListSchemaNode) {
            ListAttribute listAttribute = ListAttribute.create((LeafListSchemaNode) child, typeProviderWrapper);
            attributes.add(listAttribute);
        } else {
            throw new IllegalStateException("Unexpected running-data node " + child);
        }
    }
    Set<Rpc> rpcs = new HashSet<>();
    SchemaNode subtreeSchemaNode = (SchemaNode) subtree;
    for (UnknownSchemaNode unknownSchemaNode : subtreeSchemaNode.getUnknownSchemaNodes()) {
        if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
            String localIdentityName = unknownSchemaNode.getNodeParameter();
            QName identityQName = unknownSchemaNode.isAddedByUses() ? findQNameFromGrouping(subtree, ctx, unknownSchemaNode, localIdentityName) : QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
            // convert RpcDefinition to Rpc
            for (RpcDefinition rpcDefinition : identitiesToRpcs.get(identityQName)) {
                String name = TypeProviderWrapper.findJavaParameter(rpcDefinition);
                AttributeIfc returnType;
                if (rpcDefinition.getOutput() == null || rpcDefinition.getOutput().getChildNodes().isEmpty()) {
                    returnType = VoidAttribute.getInstance();
                } else if (rpcDefinition.getOutput().getChildNodes().size() == 1) {
                    DataSchemaNode returnDSN = rpcDefinition.getOutput().getChildNodes().iterator().next();
                    returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper, packageName);
                } else {
                    throw new IllegalArgumentException("More than one child node in rpc output is not supported. " + "Error occured in " + rpcDefinition);
                }
                List<JavaAttribute> parameters = new ArrayList<>();
                for (DataSchemaNode childNode : sortAttributes(rpcDefinition.getInput().getChildNodes())) {
                    if (childNode.isAddedByUses() == false) {
                        // skip
                        // refined
                        // context-instance
                        checkArgument(childNode instanceof LeafSchemaNode, "Unexpected type of rpc input type. " + "Currently only leafs and empty output nodes are supported, got " + childNode);
                        JavaAttribute javaAttribute = new JavaAttribute((LeafSchemaNode) childNode, typeProviderWrapper);
                        parameters.add(javaAttribute);
                    }
                }
                Rpc newRpc = new Rpc(returnType, name, rpcDefinition.getQName().getLocalName(), parameters);
                rpcs.add(newRpc);
            }
        }
    }
    return new AttributesRpcsAndRuntimeBeans(runtimeBeanEntries, attributes, rpcs);
}
Also used : RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ArrayList(java.util.ArrayList) TOAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) HashSet(java.util.HashSet) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)

Example 3 with DataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.DataSchemaNode in project controller by opendaylight.

the class FunctionImpl method create.

public static <T extends DataNodeContainer & AugmentationTarget & DataSchemaNode> TOAttribute create(final T containerSchemaNode, final TypeProviderWrapper typeProviderWrapper, final String packageName) {
    // Transfer Object: get the leaves
    final Map<String, AttributeIfc> map = new HashMap<>();
    final Map<String, String> attributeNameMap = new HashMap<>();
    for (final DataSchemaNode dataSchemaNode : containerSchemaNode.getChildNodes()) {
        try {
            final String yangName = dataSchemaNode.getQName().getLocalName();
            map.put(yangName, createInnerAttribute(dataSchemaNode, typeProviderWrapper, packageName));
        } catch (final IllegalArgumentException e) {
            throw new IllegalStateException("Unable to create TO", e);
        }
    }
    return new TOAttribute(containerSchemaNode, map, attributeNameMap, containerSchemaNode.getDescription().orElse(null), packageName);
}
Also used : HashMap(java.util.HashMap) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode)

Example 4 with DataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.DataSchemaNode in project controller by opendaylight.

the class DataNormalizationOperation method fromSchemaAndQNameChecked.

private static DataNormalizationOperation<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) throws DataNormalizationException {
    final Optional<DataSchemaNode> potential = findChildSchemaNode(schema, child);
    if (!potential.isPresent()) {
        throw new DataNormalizationException(String.format("Supplied QName %s is not valid according to schema %s, potential children nodes: %s", child, schema, schema.getChildNodes()));
    }
    final DataSchemaNode result = potential.get();
    // We try to look up if this node was added by augmentation
    if (schema instanceof DataSchemaNode && result.isAugmenting()) {
        return fromAugmentation(schema, (AugmentationTarget) schema, result);
    }
    return fromDataSchemaNode(result);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode)

Example 5 with DataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.DataSchemaNode in project controller by opendaylight.

the class DataNormalizationOperation method findChildSchemaNode.

private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) {
    DataSchemaNode potential = parent.getDataChildByName(child);
    if (potential == null) {
        final Iterable<ChoiceSchemaNode> choices = FluentIterable.from(parent.getChildNodes()).filter(ChoiceSchemaNode.class);
        potential = findChoice(choices, child);
    }
    return Optional.fromNullable(potential);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)

Aggregations

DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)9 HashMap (java.util.HashMap)4 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)3 QName (org.opendaylight.yangtools.yang.common.QName)3 HashSet (java.util.HashSet)2 DependencyAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute)2 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)2 ListAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)2 ListDependenciesAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute)2 TOAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute)2 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)2 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 IdentitySchemaNode (org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)2 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)2 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)2 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)2 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)2 UnknownSchemaNode (org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode)2 ArrayList (java.util.ArrayList)1