/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.runtime.api; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import com.google.common.annotations.Beta; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import java.util.AbstractMap.SimpleEntry; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.Set; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.mdsal.binding.model.api.DefaultType; import org.opendaylight.mdsal.binding.model.api.GeneratedType; import org.opendaylight.mdsal.binding.model.api.MethodSignature; import org.opendaylight.mdsal.binding.model.api.ParameterizedType; import org.opendaylight.mdsal.binding.model.api.Type; import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder; import org.opendaylight.yangtools.yang.binding.Action; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.model.api.ActionDefinition; import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; import org.opendaylight.yangtools.yang.model.api.AugmentationTarget; import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode; import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus; import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema; import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model, * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}. * *
Some of this information are for example list of all available children for cases
* {@link #getChoiceCaseChildren(DataNodeContainer)}, since choices are augmentable and new choices may be introduced
* by additional models. Same goes for all possible augmentations.
*/
@Beta
public abstract class AbstractBindingRuntimeContext implements BindingRuntimeContext {
private static final Logger LOG = LoggerFactory.getLogger(AbstractBindingRuntimeContext.class);
private final LoadingCache Returned schema is schema definition from which augmentation class was generated.
* This schema is isolated from other augmentations. This means it contains
* augmentation definition as was present in original YANG module.
*
* Children of returned schema does not contain any additional augmentations,
* which may be present in runtime for them, thus returned schema is unsuitable
* for use for validation of data.
*
* For retrieving {@link AugmentationSchemaNode}, which will contains
* full model for child nodes, you should use method
* {@link #getResolvedAugmentationSchema(DataNodeContainer, Class)}
* which will return augmentation schema derived from supplied augmentation target
* schema.
*
* @param augClass Augmentation class
* @return Schema of augmentation or null if augmentaiton is not known in this context
* @throws IllegalArgumentException If supplied class is not an augmentation
*/
@Override
public final @Nullable AugmentationSchemaNode getAugmentationDefinition(final Class> augClass) {
checkArgument(Augmentation.class.isAssignableFrom(augClass),
"Class %s does not represent augmentation", augClass);
return getTypes().findAugmentation(DefaultType.of(augClass)).orElse(null);
}
/**
* Returns defining {@link DataSchemaNode} for supplied class.
*
* Returned schema is schema definition from which class was generated.
* This schema may be isolated from augmentations, if supplied class
* represent node, which was child of grouping or augmentation.
*
* For getting augmentation schema from augmentation class use
* {@link #getAugmentationDefinition(Class)} instead.
*
* @param cls Class which represents list, container, choice or case.
* @return Schema node, from which class was generated.
*/
@Override
public final DataSchemaNode getSchemaDefinition(final Class> cls) {
checkArgument(!Augmentation.class.isAssignableFrom(cls), "Supplied class must not be an augmentation (%s is)",
cls);
checkArgument(!Action.class.isAssignableFrom(cls), "Supplied class must not be an action (%s is)", cls);
return (DataSchemaNode) getTypes().findSchema(DefaultType.of(cls)).orElse(null);
}
@Override
public final ActionDefinition getActionDefinition(final Class extends Action, ?, ?>> cls) {
return (ActionDefinition) getTypes().findSchema(DefaultType.of(cls)).orElse(null);
}
@Override
public final Entry