*/
package org.opendaylight.mdsal.binding.runtime.api;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.Multimap;
-import java.util.Collection;
-import java.util.Map;
import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.binding.model.api.Type;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
/**
* The result of BindingGenerator run. Contains mapping between Types and SchemaNodes.
*/
@Beta
-public final class BindingRuntimeTypes implements EffectiveModelContextProvider, Immutable {
- private final @NonNull EffectiveModelContext schemaContext;
- private final ImmutableMap<Type, AugmentationSchemaNode> typeToAugmentation;
- private final ImmutableBiMap<Type, WithStatus> typeToSchema;
- private final ImmutableMultimap<Type, Type> choiceToCases;
- private final ImmutableMap<QName, Type> identities;
+public interface BindingRuntimeTypes extends EffectiveModelContextProvider, RuntimeTypeContainer, Immutable {
- public BindingRuntimeTypes(final EffectiveModelContext schemaContext,
- final Map<Type, AugmentationSchemaNode> typeToAugmentation,
- final BiMap<Type, WithStatus> typeToDefiningSchema, final Multimap<Type, Type> choiceToCases,
- final Map<QName, Type> identities) {
- this.schemaContext = requireNonNull(schemaContext);
- this.typeToAugmentation = ImmutableMap.copyOf(typeToAugmentation);
- this.typeToSchema = ImmutableBiMap.copyOf(typeToDefiningSchema);
- this.choiceToCases = ImmutableMultimap.copyOf(choiceToCases);
- this.identities = ImmutableMap.copyOf(identities);
- }
+ Optional<IdentityRuntimeType> findIdentity(QName qname);
- @Override
- public EffectiveModelContext getEffectiveModelContext() {
- return schemaContext;
- }
+ Optional<RuntimeType> findSchema(JavaTypeName typeName);
- public Optional<AugmentationSchemaNode> findAugmentation(final Type type) {
- return Optional.ofNullable(typeToAugmentation.get(type));
- }
+ Optional<InputRuntimeType> findRpcInput(QName rpcName);
- public Optional<Type> findIdentity(final QName qname) {
- return Optional.ofNullable(identities.get(qname));
- }
-
- public Optional<WithStatus> findSchema(final Type type) {
- return Optional.ofNullable(typeToSchema.get(type));
- }
-
- public Optional<Type> findType(final WithStatus schema) {
- return Optional.ofNullable(typeToSchema.inverse().get(schema));
- }
-
- public Multimap<Type, Type> getChoiceToCases() {
- return choiceToCases;
- }
-
- public Collection<Type> findCases(final Type choiceType) {
- return choiceToCases.get(choiceType);
- }
+ Optional<OutputRuntimeType> findRpcOutput(QName rpcName);
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("typeToAugmentation", typeToAugmentation)
- .add("typeToSchema", typeToSchema)
- .add("choiceToCases", choiceToCases)
- .add("identities", identities)
- .toString();
+ default @Nullable RuntimeType schemaTreeChild(final Absolute path) {
+ final var it = path.getNodeIdentifiers().iterator();
+ var tmp = schemaTreeChild(it.next());
+ while (it.hasNext() && tmp instanceof RuntimeTypeContainer) {
+ tmp = ((RuntimeTypeContainer) tmp).schemaTreeChild(it.next());
+ }
+ return tmp;
}
}