import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
return Optional.absent();
}
- public static Optional<ChoiceCaseNode> findInstantiatedCase(final ChoiceNode instantiatedChoice, final ChoiceCaseNode schema) {
- ChoiceCaseNode potential = instantiatedChoice.getCaseNodeByName(schema.getQName());
+ public static Optional<ChoiceCaseNode> findInstantiatedCase(final ChoiceNode instantiatedChoice, final ChoiceCaseNode originalDefinition) {
+ ChoiceCaseNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName());
+ if(originalDefinition.equals(potential)) {
+ return Optional.of(potential);
+ }
if (potential != null) {
+ SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential);
+ if (originalDefinition.equals(potentialRoot)) {
+ return Optional.of(potential);
+ }
+ }
+ // We try to find case by name, then lookup its root definition
+ // and compare it with original definition
+ // This solves case, if choice was inside grouping
+ // which was used in different module and thus namespaces are
+ // different, but local names are still same.
+ //
+ // Still we need to check equality of definition, because local name is not
+ // sufficient to uniquelly determine equality of cases
+ //
+ potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName().getLocalName());
+ if(potential != null && (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(potential)))) {
return Optional.of(potential);
}
- // FIXME: Probably requires more extensive check
- // e.g. we have one choice and two augmentations from different
- // modules using same local name
- // but different namespace / contents
- return Optional.fromNullable(instantiatedChoice.getCaseNodeByName(schema.getQName().getLocalName()));
+ return Optional.absent();
}
}