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.yangtools.yang.binding.Action;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
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;
@Override
public final <T extends Augmentation<?>> AugmentationSchemaNode getAugmentationDefinition(final Class<T> augClass) {
- return getTypes().findAugmentation(DefaultType.of(augClass)).orElse(null);
+ return getTypes().findAugmentation(Type.of(augClass)).orElse(null);
}
@Override
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);
+ return (DataSchemaNode) getTypes().findSchema(Type.of(cls)).orElse(null);
+ }
+
+ @Override
+ public final DataSchemaNode findChildSchemaDefinition(final DataNodeContainer parentSchema,
+ final QNameModule parentNamespace, final Class<?> childClass) {
+ final DataSchemaNode origDef = getSchemaDefinition(childClass);
+ // Direct instantiation or use in same module in which grouping was defined.
+ DataSchemaNode sameName;
+ try {
+ sameName = parentSchema.dataChildByName(origDef.getQName());
+ } catch (final IllegalArgumentException e) {
+ LOG.trace("Failed to find schema for {}", origDef, e);
+ sameName = null;
+ }
+
+ final DataSchemaNode childSchema;
+ if (sameName != null) {
+ // Check if it is:
+ // - exactly same schema node, or
+ // - instantiated node was added via uses statement and is instantiation of same grouping
+ if (origDef.equals(sameName) || origDef.equals(getRootOriginalIfPossible(sameName))) {
+ childSchema = sameName;
+ } else {
+ // Node has same name, but clearly is different
+ childSchema = null;
+ }
+ } else {
+ // We are looking for instantiation via uses in other module
+ final QName instantiedName = origDef.getQName().bindTo(parentNamespace);
+ final DataSchemaNode potential = parentSchema.dataChildByName(instantiedName);
+ // We check if it is really instantiated from same definition as class was derived
+ if (potential != null && origDef.equals(getRootOriginalIfPossible(potential))) {
+ childSchema = potential;
+ } else {
+ childSchema = null;
+ }
+ }
+
+ return childSchema;
+ }
+
+ private static @Nullable SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
+ SchemaNode previous = null;
+ SchemaNode next = getOriginalIfPossible(data);
+ while (next != null) {
+ previous = next;
+ next = getOriginalIfPossible(next);
+ }
+ return previous;
+ }
+
+ private static @Nullable SchemaNode getOriginalIfPossible(final SchemaNode node) {
+ return node instanceof DerivableSchemaNode ? ((DerivableSchemaNode) node).getOriginal().orElse(null) : null;
}
@Override
public final ActionDefinition getActionDefinition(final Class<? extends Action<?, ?, ?>> cls) {
- return (ActionDefinition) getTypes().findSchema(DefaultType.of(cls)).orElse(null);
+ return (ActionDefinition) getTypes().findSchema(Type.of(cls)).orElse(null);
}
@Override
public final Absolute getActionIdentifier(final Class<? extends Action<?, ?, ?>> cls) {
- return getTypes().findSchemaNodeIdentifier(DefaultType.of(cls)).orElse(null);
+ return getTypes().findSchemaNodeIdentifier(Type.of(cls)).orElse(null);
}
@Override
@Override
public final Entry<GeneratedType, WithStatus> getTypeWithSchema(final Class<?> type) {
- return getTypeWithSchema(getTypes(), DefaultType.of(type));
+ return getTypeWithSchema(getTypes(), Type.of(type));
}
private static @NonNull Entry<GeneratedType, WithStatus> getTypeWithSchema(final BindingRuntimeTypes types,
@Override
public final Set<Class<?>> getCases(final Class<?> choice) {
- final Collection<Type> cazes = getTypes().findCases(DefaultType.of(choice));
+ final Collection<Type> cazes = getTypes().findCases(Type.of(choice));
final Set<Class<?>> ret = new HashSet<>(cazes.size());
for (final Type caze : cazes) {
try {