import static com.google.common.base.Verify.verify;
import com.google.common.base.Stopwatch;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.SetMultimap;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeTypes;
+import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.IdentityRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.ModuleRuntimeType;
private final Map<QName, OutputRuntimeType> rpcOutputs = new HashMap<>();
// All RpcInputs, indexed by their RPC's QName
private final Map<QName, InputRuntimeType> rpcInputs = new HashMap<>();
+ // All known 'choice's to their corresponding cases
+ private final SetMultimap<JavaTypeName, CaseRuntimeType> choiceToCases = HashMultimap.create();
private BindingRuntimeTypesFactory() {
// Hidden on purpose
LOG.debug("Indexed {} generators in {}", moduleGens.size(), sw);
return new DefaultBindingRuntimeTypes(context, factory.modules, factory.allTypes, factory.identities,
- factory.rpcInputs, factory.rpcOutputs);
+ factory.rpcInputs, factory.rpcOutputs, factory.choiceToCases);
}
private void indexModules(final Map<QNameModule, ModuleGenerator> moduleGens) {
final var prev = allTypes.put(name, type);
verify(prev == null || prev == type, "Conflict on runtime type mapping of %s between %s and %s",
name, prev, type);
+
+ // Global indexing of cases generated for a particular choice. We look at the Generated type
+ // and make assumptions about its shape -- which works just fine without touching the
+ // ChoiceRuntimeType for cases.
+ if (type instanceof CaseRuntimeType) {
+ final var ifaces = ((GeneratedType) javaType).getImplements();
+ // The appropriate choice and DataObject at the very least. The choice interface is the first
+ // one mentioned.
+ verify(ifaces.size() >= 2, "Unexpected implemented interfaces %s", ifaces);
+ choiceToCases.put(ifaces.get(0).getIdentifier(), (CaseRuntimeType) type);
+ }
}
}
indexRuntimeTypes(gen);